Search code examples
pythoncanopy

How to stop an execution of python script under Enthought Canopy?


I'm using Enthought Canopy. Something that bothers me is that I couldn't figure out how to stop or abort an running script. Usually pressing "Ctrl + C" would stop the execution of an script (as in IDLE and MATLAB), however this isn't the case in Canopy.

In canopy, the "Interrupt Kernel" function under "Run" tab barely works... I could use "Restart Kernel (CTRL + .) instead, however this would cause a restart of the kernel and everything (variables etc.) that have been done or retrieved in the execution would be lost...

Could someone show me how to stop (meaning just stop running a script) without having to restart? Thank you!


Solution

  • Interrupt Kernel is the normal way; however the nature of Python as a unified interactive environment means that if it's really deep in the execution of a C extension, you have no other way than by Restarting Kernel, losing your existing results, as you've discovered.

    On the bright side, your command history is saved, making it much easier to recreate.

    Or, if you don't have too many values to recover, and can exercise a pound of prevention, see the ipython %store magic: http://ipython-docs.readthedocs.org/en/latest/config/extensions/storemagic.html