How to exit script in spyder?

I am using WinPython Spyder. When I create a new script with a command exit()and run it there, this command kills the kernel:

It seems that the core died unexpectedly. Use Restart Kernel to continue using this console.

What is the right way to stop a script in this runtime?

+4
source share
2 answers

Can

  • exit the script by creating a custom exception like

    raise Exception('exit')
    

    or

  • encapsulate the code in a function mainand use it returninternally.

If you do not want to change the script,

  • Switch to "Run in a new specialized Python interpreter" or

  • IPython:

    def exit_handler(): raise Exception("exit()"), get_ipython().ask_exit = exit_handler
    
+9

, Spyderlib Issue 1974 # 4 . , , , script spyder.

def f(): raise Exception("Found exit()")
+3

All Articles