2

I have the problem that for debugging purposes I drop into an IPython shell in a loop:

for x in large_list:
  if x.looks_bad():
    import IPython
    IPython.embed()

From there I may want to terminate the parent program, because after debugging the problem cause, embed() would be called a lot of times. sys.exit(1) is caught by IPython, so I cannot use that.

1
  • This is actually a similar question as 173278, just from IPython instead of the unittest module. Commented Sep 6, 2016 at 13:55

1 Answer 1

4

sys.exit just raises the SystemExit exception. The following works by hard-killing the program:

import os
os._exit(1)

To easier find this in my IPython history with Ctrl-r exit (the last line will not be saved to the history), I actually wrote this line once, with a deliberate typo:

import os; os._exit(1)_
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.