Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mpacer opened this issue Jan 20, 2016 · 4 comments
Milestone

Comments

@mpacer
Copy link
Member

mpacer commented Jan 20, 2016

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.

Carreau added a commit to Carreau/ipython that referenced this issue Jan 20, 2016
This is use full in case where an IPython embed instance is created in a loop:

    from IPython import embed
    while True:
        embed(header="You will be stuck there")

Now using `%raise_on_exist True` in an embeded shell allows the embeded
instannce to raise on exit.

Potential improvement would be flags to pass a custom exception type as
well as a custom message to raise.

Closes ipython#9149
Carreau added a commit to Carreau/ipython that referenced this issue Jan 20, 2016
This is use full in case where an IPython embed instance is created in a loop:

    from IPython import embed
    while True:
        embed(header="You will be stuck there")

Now using `%raise_on_exist True` in an embeded shell allows the embeded
instannce to raise on exit.

Potential improvement would be flags to pass a custom exception type as
well as a custom message to raise.

Closes ipython#9149
@Carreau Carreau added this to the 5.0 milestone Jan 20, 2016
@takluyver
Copy link
Member

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.

@takluyver takluyver modified the milestones: 4.1, 5.0 Jan 26, 2016
@s2t2
Copy link

s2t2 commented May 25, 2018

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)

@kolypto
Copy link

kolypto commented Oct 15, 2019

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

@pranavtushar
Copy link

@s2t2 exit is working with the current version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants