├── colab_keep_alive.exe ├── colab_keep_alive.ahk └── README.md /colab_keep_alive.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sour4bh/stop-cursing-colab/HEAD/colab_keep_alive.exe -------------------------------------------------------------------------------- /colab_keep_alive.ahk: -------------------------------------------------------------------------------- 1 | 2 | KeepAlive(ColabWinTitle, Interval){ 3 | Loop 4 | { 5 | Sleep, 1000 * 3 6 | if WinExist(ColabWinTitle) 7 | { 8 | WinActivate ; Automatically uses the window found above. 9 | WinMaximize ; same 10 | Sleep, 2000 11 | MouseClick, left, 1750, 250, 1, 30 12 | Send, {WheelDown 10} 13 | Send, {WheelDown 20} 14 | send, {PgDn 2} 15 | MouseClick, left, 1750, 500, 1, 30 16 | send, {PgUp 4} 17 | send, {PgDn 8} 18 | } 19 | else{ 20 | MsgBox, , Halt : No Such Window , Did not find Window : %ColabWinTitle% 21 | Return 22 | } 23 | Sleep, Interval 24 | } 25 | } 26 | 27 | 28 | InputBox, ColabFileName, Colab Keep Alive Script, Enter the Google Colab filename 29 | ColabWinTitle := ColabFileName . " - Colaboratory - Google Chrome" 30 | if WinExist(ColabWinTitle){ 31 | WinActivate 32 | InputBox, Interval, Keep Alive : %ColabWinTitle%, Enter an interval (in minutes) to emulate mouse and keyboard behaviour : 33 | if Interval is not integer 34 | { 35 | MsgBox, , Halt : Bad Type, Enter an Integer for the Interval 36 | Return 37 | } 38 | else{ 39 | MsgBox, , Interval Set, interval set for %Interval% minutes. 40 | Interval := 1000 * 60 * Interval 41 | KeepAlive(ColabWinTitle , Interval) 42 | } 43 | } 44 | else{ 45 | MsgBox, , Halt : No Such Window, Did not find Window : %ColabWinTitle% 46 | Return 47 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #### stop-cursing-colab 2 | 3 | # A simple AHK script to keep Google Colab alive: 4 | 5 | This script uses AutoHotKey, an automation scripting language and tool, to emulate human interface device interactions on Google Colab notebook to avoid runtime inactivity timeouts. 6 | 7 | > **Note:** this works only on Windows OS! 8 | 9 | Read the [medium article](https://medium.com/analytics-vidhya/how-to-save-google-colab-notebooks-from-runtime-timeouts-4aa133375a7e) for more information. 10 | 11 | ## Usage 12 | 13 | ##### Executable Binary (No dependencies) : 14 | > - Download the .exe from the [releases](https://github.com/sour4bh/stop-cursing-colab/releases) section. 15 | > - Just double-click the executable `colab_keep_alive.exe` 16 | > - Enter the file name of the colab `` 17 | > - Set the interval for HID interactions (in mins) 18 | > - Done. 19 | 20 | ##### CIY using Authotkey : 21 | > - Install [AutoHotKey](https://www.autohotkey.com/download/ahk-install.exe) 22 | > - Double-click `colab_keep_alive.ahk` to run. [ To compile, right click > compile ] 23 | > - Enter the file name of the colab `` 24 | > - Set the interval for HID interactions (in mins) 25 | > - Done. 26 | 27 | ## Troubleshoot 28 | - The title of the window should be ` - Colaboratory - Google Chrome` 29 | - If there are multiple tabs in the Chrome Window, make sure colab notebook is the active one. 30 | - Make sure power sleep/hibernate timeout is greater than script's interval 🙃 31 | --------------------------------------------------------------------------------