Colab prevents disconnection and clearing methods

Colab prevents disconnection (disconnection)

When using google colab, if there is no interaction for a long time, the connection may be dropped and all data will be lost.

Resolution (valid until February 2023)

Some methods on the Internet are no longer valid. The following is the method that I personally tested in February 2023

Press Fn+F12, or Ctrl+Shift+i, or right-click outside the code to check, open the development and debugging tool, enter a piece of code in the Console and press Enter

function ConnectButton(){
    
    
    console.log("Connect pushed"); 
    document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click() 
}
setInterval(ConnectButton,60000);

The above code will click the button on the page every minute (60000ms) to keep the connection. The actual effect will be that the resource window will be displayed one minute after the start, and the resource window will disappear after another minute, thus keeping it active.

insert image description here

The output result is intervalIdas 6843

When the training is over and you don't need to maintain the click effect for one minute, use the following statement to clear

clearInterval(intervalId) # intervalId换成具体的数字

Guess you like

Origin blog.csdn.net/jinniulema/article/details/128994223