如何从 IPython 中止 python 脚本(控制台)
How to abort python script from IPython (console)
我正在使用 IPython(控制台)中的 embed()
与我的脚本进行交互。每当我按 CTRL+D 时,它都会退出交互模式并在 embed()
调用后继续下一个命令。
如何中止完整的python脚本,避免它在embed()
之后从交互式python执行进一步的命令?
我尝试过的:
CTRL+C : 仅在 IPython
中取消我当前的命令
CTRL+D :离开 IPython 并继续我脚本中的下一个命令
键入 exit() :与 CTRL+D
相同
这是一个示例脚本:
#!/usr/bin/env python
from IPython import embed
print 'hello world'
embed()
print 'I dont want to reach here if I decide to quit from the IPython terminal!'
一个选项是从 IPython 会话中删除进程 ID:
$ python test_embed.py
hello world
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, May 28 2015, 17:04:42)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import os
In [2]: os.kill(os.getpid(), 9)
Killed: 9
编辑: 看起来用 Ctrl-\
发送 SIGQUIT 也会完全终止脚本。
我正在使用 IPython(控制台)中的 embed()
与我的脚本进行交互。每当我按 CTRL+D 时,它都会退出交互模式并在 embed()
调用后继续下一个命令。
如何中止完整的python脚本,避免它在embed()
之后从交互式python执行进一步的命令?
我尝试过的:
CTRL+C : 仅在 IPython
中取消我当前的命令CTRL+D :离开 IPython 并继续我脚本中的下一个命令
键入 exit() :与 CTRL+D
相同这是一个示例脚本:
#!/usr/bin/env python
from IPython import embed
print 'hello world'
embed()
print 'I dont want to reach here if I decide to quit from the IPython terminal!'
一个选项是从 IPython 会话中删除进程 ID:
$ python test_embed.py
hello world
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, May 28 2015, 17:04:42)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import os
In [2]: os.kill(os.getpid(), 9)
Killed: 9
编辑: 看起来用 Ctrl-\
发送 SIGQUIT 也会完全终止脚本。