0

I want to execute a command on disconnect event of google collab script, but i dont know how to detect if it's about to disconnect to execute it

For more detail : How to prevent Google Colab from disconnecting? Google Colab notebooks have an idle timeout of 90 minutes and absolute timeout of 12 hours. This means, if user does not interact with his Google Colab notebook for more than 90 minutes, its instance is automatically terminated. Also, maximum lifetime of a Colab instance is 12 hours.

so i want to execute a command when the collab notebook is about to terminate but i dont know if there is a event like that so the user can call command on that event or a way to detect if the collab notebook is about disconnecting

Thanks

kura asa
  • 1
  • 1

1 Answers1

-1

You can use this for executing command on thread, but I don't know if this is going to keep it alive.

import subprocess
import threading
import time

def run_shell_command(command, wait):
    while True:
      time.sleep(wait)
      subprocess.check_output(command, shell=True)

t = threading.Thread(target=run_shell_command, args=["touch hi", 3])

t.start()
can
  • 309
  • 1
  • 4
  • 13