I am using WinPython's Spyder. When I am creating a new script with the command exit()
, and run it there, this command kills the kernel:
It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.
What's the right way to stop a script in this runtime environment?
As Robert Pollak suggest, the comment in Spyderlib Issue 1974 #4 is a better solution. Just define a function which cause an exception, and call this function if you want to stop the execute of script inside spyder.
One can
exit the script by raising a custom exception like
or
encapsulate the code into a
main
function and usereturn
inside.If one doesn't want to change the script, one can
Switch to "Execute in a new dedicated Python interpreter" or
register an exit handler at the IPython console: