如何在不终止父进程的情况下中断失控的ipython评估? [英] How to interrupt a runaway ipython evaluation without terminating the parent process?
问题描述
有时 正在进行的 ipython
评估不会响应一个甚至几个 , Ctrl-C
来自键盘 1 。
Sometimes it happens that an ongoing ipython
evaluation won't respond to one, or even several, Ctrl-C
's from the keyboard1.
还有其他方法可以使用 ipython
过程中止当前评价,并返回其 读 状态?
Is there some other way to goose the ipython
process to abort the current evaluation, and come back to its "read" state?
也许与杀-SOMESECRETSIGNAL< ; PID>
?我尝试了一些( SIGINT
, SIGTERM
, SIGUSR1
,...)无效:要么它们没有效果(例如 SIGINT
),要么它们会杀死 ipython
过程。或者可能是一些神秘的 ipython
配置?一些哨兵文件? ......?
Maybe with kill -SOMESECRETSIGNAL <pid>
? I've tried a few (SIGINT
, SIGTERM
, SIGUSR1
, ...) to no avail: either they have no effect (e.g. SIGINT
), or they kill the ipython
process. Or maybe some arcane ipython
configuration? Some sentinel file? ... ?
1 足够快,即。当然,不可能准确地指出及时的迅速程度;它取决于形势,延迟的时间的可靠性,用户,一天的采摘在黑客新闻等的气质。
推荐答案
这取决于您决定中断时执行的位置(在python函数中,在较低级别的库中,...)。如果这通常发生在您创建的函数中,您可以尝试在函数中放置一个try / except块并捕获 KeyboardInterrupt
异常。它可能不会突破低级库(如果确实在你运行的地方),但它应该阻止ipython解释器退出。
It depends on where execution is occurring when you decide to interrupt (in a python function, in a lower level library,...). If this commonly occurs within a function you have created, you can try putting a try/except block in the function and catching KeyboardInterrupt
exceptions. It may not break out of a low level library (if that is indeed where you are running) but it should prevent the ipython interpreter from exiting.
这篇关于如何在不终止父进程的情况下中断失控的ipython评估?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!