KeyboardInterrupt unpredictable in Python 2.7 under ipython, how can I make it *always* abort current evaluation?

不问归期 提交于 2019-12-11 02:21:24

问题


I'm writing python code to do numerical analysis, and I've been using ipython or ipython -pylab as my command line interface. I often run into situations where some code is taking for-freaking-ever to run, and I need to stop it. However, Ctrl-C is problematic; sometimes it works, sometimes it doesn't do anything, and sometimes it quits the whole process (very annoying.) How can I make it so that hitting Ctrl-C always always works? It seems as if the times that it doesn't work are those where it is executing code in some other module.

Thanks much.


回答1:


You are probably running a background thread that is swallowing the signal, there is no real way of prohibiting that, compare http://www.dabeaz.com/python/GIL.pdf



来源:https://stackoverflow.com/questions/6510138/keyboardinterrupt-unpredictable-in-python-2-7-under-ipython-how-can-i-make-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!