There's a %kill_embedded
command in IPython.
It doesn't put you directly back to the shell prompt, but it skips the other embed instances.
from IPython import embed
for item in range(5):
print 'embedding', item
embed()
And here's the output:
$ python my_example_program.py
embedding 0
Python 2.7.9 (default, Dec 13 2014, 22:30:33)
Type "copyright", "credits" or "license" for more information.
IPython 1.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]: print item
0
In [2]: ^D
embedding 1
Python 2.7.9 (default, Dec 13 2014, 22:30:33)
Type "copyright", "credits" or "license" for more information.
IPython 1.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 [2]: %kill_embedded
Are you sure you want to kill this embedded instance (y/n)? [y/N] y
This embedded IPython will not reactivate anymore once you exit.
In [3]: print item
1
In [4]:
embedding 2
embedding 3
embedding 4
$
UPD (06.03.2016): Seems that the %kill_embedded
feature is kind of broken in IPython 4.0; you can use %exit_raise
which will raise an exception and return back to the shell.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…