【发布时间】:2018-11-15 14:15:19
【问题描述】:
我正在使用 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')
【问题讨论】:
-
请点击突出显示的段落以查看我在 spyder ipython 控制台中的输出图像
-
你为什么要这样做?
-
简单来说就是解决第三方API调用内存过大的问题。在使用 python 对第三方应用程序 API 发出超过一定数量的调用后,我遇到了内存问题。所以,我想在某些调用之后在 spyder 中杀死 ipython 并重新启动我的内核以完成其余的调用。
-
你可以释放内存。或者,您可以使用 ipython 魔法清除所有变量。这将导致一个“新”内核。