I am using WinPython Spyder. When I create a new script with a command exit()and run it there, this command kills the kernel:
exit()
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?
Can
exit the script by creating a custom exception like
raise Exception('exit')
or
encapsulate the code in a function mainand use it returninternally.
main
return
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
, Spyderlib Issue 1974 # 4 . , , , script spyder.
def f(): raise Exception("Found exit()")