Prevent colab from disconnecting with console js

P

This quick note is one solution (may not optimal) to prevent Colab from disconnecting during training your deep learning model.

disconnect Problem

Recently, my Google Colab notebook often gets disconnected after a while, and the data is lost. I searched and found a solution. So reshare this here.

SOLUTION

So to prevent this, we add a JS code to the console. Its purpose is to keep on clicking the page and prevent it from idling. So, I follow these steps:

  • Open the chrome console, Ctrl+ Shift + i to open inspector view
Chrome console
  • Goto console.
Get to the editable area
  • Paste and run the following code in the console:
function ClickConnect(){
console.log("Working");
document.querySelector("colab-toolbar-button#connect").click()
}
setInterval(ClickConnect,60000)

And remember to press Enter to start the script, it then can prevent your Colab notebook from disconnecting.

About the author

Tung Nguyen

I got my bachelor of telecommunication engineering in Shanghai University, Master of IST for Paris Sud 11, and PhD from Auckland University of Technology. I am interested in combining AI/ML, Mobile and Cloud platform to build awesome applications.

1 comment

By Tung Nguyen

PetaMinds focuses on developing the coolest topics in data science, A.I, and programming, and make them so digestible for everyone to learn and create amazing applications in a short time.

Categories