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.
Use the pyautogui module to click on the screen. Install normally using pip.
pip install pyautogui
Let the program run in Colab as usual. Any browser is OK.
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')
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.
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