如何在IPython内核重启后运行代码

时间:2018-06-06 01:45:36

标签: python ipython spyder

我使用python-64bit ver3.6.5在spyder中运行此代码。有人可以帮助我如何在ipython重启后运行命令

import IPython
import time

def restart_ipyhton():
    app = IPython.Application.instance()
    app.kernel.do_shutdown(True)  

print('before restart')
restart_ipyhton()
time.sleep(10)
print('after restart')

Even though I specified a delay of 10 seconds, ipython kernel executed the statements "print('after restart')" before it died. Can someone help me how can I run commands after ipython restarts

1 个答案:

答案 0 :(得分:0)

Spyder维护者在这里)问题是内核重启是异步调用,即它们是在外部进程中执行的,当调用完成时和新内核时无法从代码中分辨出来是可用的。那是因为代码在将要被杀死的内核中运行。

所以,据我所知,不可能做你想做的事(但我不是Jupyter架构的专家)。

相关问题