我正在尝试通过单元重新启动 Google Colab Jupyter Notebook 中的内核。之前给出的选项:
import os
os._exit(00)
没问题,但在我看来,这不是一种非常“Pythonic”的重启内核的方式。另一种选择:
from IPython.core.display import HTML
HTML("<script>Jupyter.notebook.kernel.restart()</script>")
对我来说似乎更“Pythonic”(更好),但它不起作用。
对于 Google Colab 有什么我应该做的事情吗?
致以诚挚的问候,
古斯塔沃,
只需转到选项菜单中的“运行时”,然后单击“重置所有运行时..”。
它可以帮助我重新启动内核,就像我尝试运行此命令时在 jupyter 笔记本中发生的情况一样:
tf.executing_eagerly()
我曾经使用过这个命令:
condacolab KERNEL RESTART \
print("Restarting of kernel...") \
get_ipython().kernel.do_shutdown(True)
将其写入单元格并执行:
import os
os.kill(os.getpid(), 9)
You can use the exit() or quit() functions.