handling uncaught exceptions with pdb?

Paul Rubin http
Wed Sep 10 17:50:07 EDT 2008


I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb?  I know about setting
sys.except_hook to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level.  My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing.  Of course this presumes a certain semantics for Python
exceptions (i.e. handling one involves scanning the stack twice, once
to look for a handler and again to actually unwind the stack) and I'm
not sure if it's really done that way.  I do know that Lisp has a
requirement like that, though; so maybe there is hope.



More information about the Python-list mailing list