Search code examples
google-colaboratory

Prevent a Google Colab Process from being disconnected


Suppose I have to move out 3 hours away from my girlfriend's apartment, and I am running a Colab Environment. I can't stop the process and I need to bring my computer with me. How can I prevent the running process from being disconnected?

I have tried that question, but I think the Google Colab Interface has changed a bit, so the answers are no longer up-to-date.


Solution

  • There are many answers there. Currently for me works perfectly to go to the console and type

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

    Take note that this should prevent disconnecting after each 1.5 hours of inactivity, but each runtime, if you don't have Colab Pro, will be terminated after 12 hours.

    Edit:

    I have tested my self and come up that this works:

    function ClickConnect(){
        console.log("Clicked on connect button"); 
        document.querySelector("#ok").click()
    }
    setInterval(ClickConnect,60000)
    

    Note that it will throw an error, its ok, it means that the Disconnection notification is not shown. Once it appear it will be clicked to reconnect.