How to prevent Google Colab from disconnecting ?

Shivam Rawat
2 min readJul 28, 2019

--

Photo by Shahadat Shemul on Unsplash

> WHAT IS GOOGLE COLAB

Google Colab is a awesome place provided by google for training models. I provides virtual machines with GPU. It provides jupyter like notebooks for programming.

Google Colab is a free cloud service and now it supports free GPU! You can: improve your Python programming language coding skills.

> PROBLEM

I was training my model but the google colab keeps disconnecting after 30 mins automatically if I do not respond. And my data is lost.

> SOLUTION

UPDATE :

Try this if works

function ClickConnect(){var reconnect = document.querySelector(“colab-toolbar-button#connect”)if(reconnect != null){console.log(“working”)reconnect.click()}}const tensorInterval = setInterval(ClickConnect,60000)// Then to stop clicking paste thisclearInterval(tensorInterval)

UPDATE FEB:

Try if this works. If not try the original article.

function ClickConnect(){
{
console.log(“Working”);
document.querySelector(“colab-connect-button”).shadowRoot.getElementById(‘connect’).click();
}
setInterval(ClickConnect,60000)

Thanks To:

https://medium.com/@daianan

So to prevent this just run the following code in the console and it will prevent you from disconnecting.

Ctrl+ Shift + i to open inspector view . Then goto console.

function ClickConnect(){
console.log("Working");
document.querySelector("colab-toolbar-button#connect").click()
}
setInterval(ClickConnect,60000)

It would keep on clicking the page and prevent it from disconnecting.

It solved the issue for me.

ERRORS :

People have been reporting for errors.

function ClickConnect(){
console.log("Working");
document.querySelector("colab-toolbar-button").click()
}setInterval(ClickConnect,60000)

Try this. I didnt work on google colab for a long time there for thought there might be changes but as of now the site is same and the default code should be working. But in case it didnot work use this one.

There might be an error if the console window is taking a lot of image and the connect button is not visible in the page.

If the error persist contact me.

SUPPORT

If you would like to support me visit https://ko-fi.com/shivamrawat .

More articles coming soon :)

--

--

Shivam Rawat

Hi, I am a programmer working on Websites / Apps. Hobby : Unity Games , Machine Learning