Restart ipython Kernel with a command from a cell

柔情痞子 提交于 2020-04-08 00:47:27

问题


Is it possible to restart an ipython Kernel NOT by selecting Kernel > Restart from the notebook GUI, but from executing a command in a notebook cell?


回答1:


As Thomas K. suggested, here is the way to restart the ipython kernel from your keyboard:

import os
os._exit(00)



回答2:


To define a function that restarts the Jupyter kernel, I've successfully used:

from IPython.display import display_html
def restartkernel() :
    display_html("<script>Jupyter.notebook.kernel.restart()</script>",raw=True)

then calling

restartkernel()

when time for the restart.



来源:https://stackoverflow.com/questions/37751120/restart-ipython-kernel-with-a-command-from-a-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!