Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pouyaardehkhani/29a59270801a209d4960e2aefe648bbc to your computer and use it in GitHub Desktop.
Save pouyaardehkhani/29a59270801a209d4960e2aefe648bbc to your computer and use it in GitHub Desktop.
Keep Google Colab from disconnecting

Problem

I was training a deep learning model on Google Colab. I had to go somewhere for an emergency work. When I came back, I realized that Colab was disconnected; Therefore, I had to run the whole model again.

Solution

I searched on the Internet to solve this problem. I noticed that Colab will be disconnected if you don't click on the page. Here is an answer that I find:

function ClickConnect() {
  console.log('Working')
  document
    .querySelector('#top-toolbar > colab-connect-button')
    .shadowRoot.querySelector('#connect')
    .click()
}
intervalTiming = setInterval(ClickConnect, 60000)

Copy this code above to the page Console and press enter.

60000(ms) means that every 1 minute it clicks on the page.

If you don't know how to open the page Console, you can either press f12 or right_click + inspect then select the Console.

When you're done, you can reset this by typing the code bellow in the page Console:

clearInterval(intervalTiming);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment