Google Colaboratory 90-minute session disconnection countermeasures --- Use Python! ---

things to do

Even if Google Colab is running the program, if you do not touch anything, the program will stop after 90 minutes. As a countermeasure against this session expiration, How to use the add-on of Google Chrome and how to execute the script was introduced, but since the add-on did not work, I click the screen regularly in the Python program I wrote a simple program of the primitive method, so I will introduce it.

How to do

1. Install the pyautogui module

Use the pyautogui module to click on the screen. Install normally using pip. pip install pyautogui


2. Run Google Colaboratory

Let the program run in Colab as usual. Any browser is OK.

3. Run a Python program

Run the following program from the terminal or editor. For the time being, it is named for_colab.py, but you can freely name it, save it, and execute it.

for_colab.py


#! python3
# -*- coding: utf-8 -*-

#Continue to use colab

import time
import pyautogui

print()
print('''Move the mouse cursor slightly left or right every 10 minutes and click.
It will end in 12 hours. Ctrl to stop in the middle+Press c.
''')

try:
    dir = -10
    counter = 0

    while counter < 72:
        time.sleep(600)
        pyautogui.moveRel(dir, 0)
        dir = - dir

        pyautogui.click()
        counter += 1
        # print('counter:', counter)  #Comment out if you want to output when clicked

    print('Stop: 12 hours have passed')


except KeyboardInterrupt:
    print('Stop: Ctrl+End with c')


The program is very simple, wait 10 minutes in time sleep, then move the pointer slightly to the right (or left) and click. After doing it 72 times (= 12 hours), it will end.

4. Return to google colab

Go back to colab, where you started the program earlier, and check that the program is running. Create some blank cells near the end of the colab program and place the pointer in that location. that's all.

Notes

The program "for_colab.py" is clicked every 10 minutes, but according to the rules of colab, you can click within 90 minutes, so change the time sleep value to your liking. Also, if you want to make sure that you clicked when you clicked, enable the commented out PRINT statement. It's a simple program, so please change it to make it easier to use.

Google Colaboratory is very useful for machine learning training because you can use the GPU for free. Train your Google teacher while you sleep.

'-------------------- End --------------------'

Recommended Posts

Google Colaboratory 90-minute session disconnection countermeasures --- Use Python! ---
Use music21 on Google Colaboratory
How to use Google Colaboratory
Forcibly use Google Translate from python
■ [Google Colaboratory] Use morphological analysis (janome)
■ [Google Colaboratory] Use morphological analysis (MeCab)
Use Google Analytics API from Python
Use The Metabolic Disassembler on Google Colaboratory
Google colaboratory
Use cartopy without bugs in Google Colaboratory
Use TPU and Keras with Google Colaboratory
Free Python runtime environment Google Colaboratory memo
How to use Spacy Japanese model in Google Colaboratory
I can't use the darknet command in Google Colaboratory!
Building an environment to use CaboCha with google colaboratory