Skip to content

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. 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.

    def EndProgram(self):
        
        print("Exiting Program")
        FigureCanvas.close(self)
        # behaviour to trigger on exit
        sys.exit()
        # exit

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

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()