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.