Ipython: Cannot escape IPython.embed() when called repeatedly within function inside a for-loop

Created on 20 Jan 2016  ·  3Comments  ·  Source: ipython/ipython

I am running foo.py from the command line, and it includes a function has a for loop, inside of which is a function that has an IPython.embed() statement. This is to initialize an interpreter at that point within the function to have access to those local variables.

However, when trying to escape from the embedded interpreter, it only opens a new interpreter (presumably up to k times for the for loop), effectively locking that terminal.

It would be nice to have a command analogous to ipdb's q, which immediately throws an exception and exits to the CLI in which foo.py was executed.

Most helpful comment

It would be nice to have a single command that would completely stop the script's execution. Like the equivalent of:

  1. %kill_embedded (and yes, sure about it)
  2. exit
  3. "ctrl + c" (three times)

All 3 comments

Try %kill_embedded - it doesn't break out of your loop, but it should make all future calls to embed() no-ops, so that the rest of your script executes to completion.

It would be nice to have a single command that would completely stop the script's execution. Like the equivalent of:

  1. %kill_embedded (and yes, sure about it)
  2. exit
  3. "ctrl + c" (three times)

%exit_raise will raise an exception into the outer context and your code will exit

Was this page helpful?
0 / 5 - 0 ratings