'How to keep the google colab running without disconnecting in 2022

I am running my model, but the GPU keeps disconnecting after a few epochs. I googled the solution and I tried this javascript. I right-clicked then inspect the element and then go to console and paste this code.But it does not seem to work. Does anybody know any other code or ways to keep the google collab running without disconnecting

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

setInterval(ClickConnect,60000)


Solution 1:[1]

try this I hope this help you :

import time
from pynput.mouse import Controller ,Button

MouseClick = Controller()

while True:

    MouseClick.click(Button.left, 1)
    time.sleep(20)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Al Fa