Google Colab session timeout

It's 90 minutes if you close the browser. 12 hours if you keep the browser open. Additionally, if you close your browser with a code cell is running, if that same cell has not finished, when you reopen the browser it will still be running (the current executing cell keeps running even after browser is closed)


PROBLEM: I have to training my model for hours but the google colab keeps disconnecting after 30 mins automatically if I do not click frequently, leading to loss of all data.

SOLUTION:

Steps:

  1. Open the inspector view by typing Ctrl+ Shift + i and then clicking on console tab at top.
  2. Paste the below code snippet at bottom of console and hit enter
function ClickConnect(){
console.log("Working"); 
document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click();
}
setInterval(ClickConnect,60000)
  1. Believe me, that's all folks. Above code would keep on clicking the page and prevent it from disconnecting.

Below is the image showing console view of above steps:-

enter image description here

enter image description here

Alternatively you can also try below snippet:

interval = setInterval(function() { 
    console.log("working")
    var selector = "#top-toolbar > colab-connect-button"
    document.querySelector(selector).shadowRoot.querySelector("#connect").click()
    setTimeout(function() {
            document.querySelector(selector).shadowRoot.querySelector("#connect").click()
    }, 1000)
}, 60*1000)