Permalink
Browse files

Merge pull request #28 from marciomazza/master

Check to wrap sys.excepthook only once
  • Loading branch information...
gotcha committed Jul 6, 2012
2 parents 21c0989 + dd70a77 commit 50c7ede8b2c9f9b6626aca84202d3c3eac220e22
Showing with 8 additions and 4 deletions.
  1. +8 −4 ipdb/__main__.py
View
@@ -58,20 +58,24 @@ def update_stdout():
# setup stdout to ensure output is available with nose
Term.cout = sys.stdout = sys.__stdout__
+def wrap_sys_excepthook():
+ # make sure we wrap it only once or we would end up with a cycle
+ # BdbQuit_excepthook.excepthook_ori == BdbQuit_excepthook
+ if sys.excepthook != BdbQuit_excepthook:
+ BdbQuit_excepthook.excepthook_ori = sys.excepthook
+ sys.excepthook = BdbQuit_excepthook
def set_trace(frame=None):
update_stdout()
- BdbQuit_excepthook.excepthook_ori = sys.excepthook
- sys.excepthook = BdbQuit_excepthook
+ wrap_sys_excepthook()
if frame is None:
frame = sys._getframe().f_back
Pdb(def_colors).set_trace(frame)
def post_mortem(tb):
update_stdout()
- BdbQuit_excepthook.excepthook_ori = sys.excepthook
- sys.excepthook = BdbQuit_excepthook
+ wrap_sys_excepthook()
p = Pdb(def_colors)
p.reset()
if tb is None:

0 comments on commit 50c7ede

Please sign in to comment.