[英]Restarting kernel, ipython console in spyder
I am having this problem in spyder where, after I run my code and exit the gui.program, the kernel needs to manually be restarted after every time my code is ran, I sometimes even have to shut down spyder as kernel crashes.我在 spyder 中遇到了这个问题,在我运行代码并退出 gui.program 后,每次运行代码后都需要手动重新启动内核,有时我什至不得不在内核崩溃时关闭 spyder。 I am wondering if there is a way for the kernel to automatically be reset after closing the gui.program so I can run it again right after?
我想知道是否有办法让内核在关闭 gui.program 后自动重置,以便之后我可以再次运行它? This closes the program but doesn't restart the kernel.
这会关闭程序但不会重新启动内核。
def EndProgram(self):
print("Exiting Program")
FigureCanvas.close(self)
# behaviour to trigger on exit
sys.exit()
# exit
I found the issue, I had sys.exit() in my EndProgram() function as well as at the end of my code as seen here: sys.exit(app.exec_()).我发现了这个问题,我的 EndProgram() 函数中以及代码末尾都有 sys.exit(),如下所示:sys.exit(app.exec_())。 Once I took out the sys.exit() in my EndProgram function and changed sys.exit(app.exec_()) to sys.exit(), it is working perfect.
一旦我在 EndProgram 函数中取出 sys.exit() 并将 sys.exit(app.exec_()) 更改为 sys.exit(),它就可以完美运行。
Original Code原始代码
if __name__ == '__main__':
# from LoadIceberg2 import LoadData2
app = Application(sys.argv)
gui = ProgramGUI()
qr = gui.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
gui.move(qr.topLeft())
# app.processEvents()
npics=8
gui.show()
# behaviour to trigger on exit
sys.exit(app.exec_())
New code新代码
if __name__ == '__main__':
# from LoadIceberg2 import LoadData2
app = Application(sys.argv)
gui = ProgramGUI()
qr = gui.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
gui.move(qr.topLeft())
# app.processEvents()
npics=8
gui.show()
# behaviour to trigger on exit
sys.exit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.