Dragon Arrow written by Tatsuya Nakaji, all rights reserved animated-dragon-image-0164

How to prevent Google Colaboratory from disconnecting

updated on 2020-01-13

prevent Google Colaboratory from disconnecting



Cause


Google Colab notebooks have an idle timeout of 90 minutes and absolute timeout of 12 hours. This means, if user does not interact with his Google Colab notebook for more than 90 minutes, its instance is automatically terminated. Also, maximum lifetime of a Colab instance is 12 hours.


90分でセッションが切れて、12時間で完全にタイムアウトを起こす。


Solution


Set a javascript interval to click on the connect button every 60 seconds. 


1. Open chrome developer-settings (in your web-browser) with Ctrl+Shift+I (windows) (in case of mac, press Option+Command+I)

Chromeのディベロッパーツールを開く


 2. click on "console" tab and type under code on the console and press enter.

Chromeのディベロッパーツールのコンソールに以下のjavascriptを打ち込む


function ConnectButton(){
    console.log("Connect pushed"); 
    document.querySelector("#connect").click() 
}
setInterval(ConnectButton,60000); # 60000ms means 60s


Set a javascript interval to click on the connect button every 60 seconds (60000 ms)

60秒毎に接続ボタンが押されるので90分経ってもタイムアウトしない。


Finally...


Sometimes, complex code miss cause as timeout inspite of code error.

Time out isn't always caused by session out or run time out.