avatarShivam Rawat

Summary

The website provides a solution for preventing Google Colab from disconnecting after periods of inactivity by running a JavaScript function that simulates user interaction.

Abstract

Google Colab is a cloud-based service offering free GPU usage and a Jupyter notebook environment for programming and model training. A common issue faced by users is the automatic disconnection after 30 minutes of inactivity, which can lead to the loss of data. The article addresses this problem by offering a JavaScript code snippet that, when executed in the browser's console, periodically clicks the "Connect" button to keep the session active. This code is intended to prevent disconnection and data loss. The author provides updates to the code based on user feedback and encourages users to try the suggested solutions, offering additional resources for those who may encounter errors.

Opinions

  • The author acknowledges the utility of Google Colab for Python programming and machine learning tasks, highlighting its free GPU service as a significant advantage.
  • The disconnection issue is presented as a notable inconvenience that can disrupt work and lead to data loss.
  • The proposed solution involves automating user interaction through JavaScript to maintain an active session, indicating a creative workaround to the session timeout policy.
  • User feedback is considered important, as the author has updated the code snippet in response to reported errors and issues.
  • The author expresses confidence in the provided solution, stating that it has resolved the disconnection issue for them personally.
  • Readers are encouraged to support the author financially via a link to Ko-fi, suggesting that the author values recognition and support for their work.
  • The author commits to providing more content in the future, indicating an intention to continue contributing to the community.

How to prevent Google Colab from disconnecting ?

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 this
clearInterval(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 :)

JavaScript
Colab
Issue
Python
Jupyter
Recommended from ReadMedium