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. 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? This closes the program but doesn’t restart the kernel.
JavaScript
x
8
1
def EndProgram(self):
2
3
print("Exiting Program")
4
FigureCanvas.close(self)
5
# behaviour to trigger on exit
6
sys.exit()
7
# exit
8
Advertisement
Answer
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_()). Once I took out the sys.exit() in my EndProgram function and changed sys.exit(app.exec_()) to sys.exit(), it is working perfect.
Original Code
JavaScript
1
16
16
1
if __name__ == '__main__':
2
# from LoadIceberg2 import LoadData2
3
app = Application(sys.argv)
4
gui = ProgramGUI()
5
6
qr = gui.frameGeometry()
7
cp = QDesktopWidget().availableGeometry().center()
8
qr.moveCenter(cp)
9
gui.move(qr.topLeft())
10
# app.processEvents()
11
npics=8
12
gui.show()
13
14
# behaviour to trigger on exit
15
sys.exit(app.exec_())
16
New code
JavaScript
1
16
16
1
if __name__ == '__main__':
2
# from LoadIceberg2 import LoadData2
3
app = Application(sys.argv)
4
gui = ProgramGUI()
5
6
qr = gui.frameGeometry()
7
cp = QDesktopWidget().availableGeometry().center()
8
qr.moveCenter(cp)
9
gui.move(qr.topLeft())
10
# app.processEvents()
11
npics=8
12
gui.show()
13
14
# behaviour to trigger on exit
15
sys.exit()
16