Issue
I want to stop a Google Colab notebook programmatically when the thing I want to do has ended, I thought of putting a line at the end that would stop it from running. I have tried these, but none work. They all restart instead of shutting down or then just give an error.
I got these from here:
- Is there a function in google.colab module to close the runtime
- https://newbedev.com/google-colab-how-to-restart-runtime-using-python-code-or-command-line-interface
import os
os.kill(os.getpid(), 9)
import sys
sys.exit()
exit()
quit()
!kill -9 -1
There is a shortcut for ending all runtimes, (It's undefined by default by I added it as Ctrl + Shift + K), so maybe I could write a program that would virtually type those keys. But it opens a popup before shutting down and I may not be there to confirm it.
How can I do this? Thanks!
Solution
Now (since September 12th, 2022) you can do this:
from google.colab import runtime
runtime.unassign()
It was announced in this GitHub issue: https://github.com/googlecolab/colabtools/issues/2568. Thanks @HappyFace for commenting this link.
Answered By - Ayo Reis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.