Debugging an unhandled exception?
Fernando Perez
fperez528 at yahoo.com
Mon Feb 17 21:26:18 EST 2003
Paul Rubin wrote:
> Is there any way to launch the debugger on raising an unhandled
> exception?
You may try ipython (http://www-hep.colorado.edu/~fperez/ipython) as your
python interactive shell.
Under ipython, typing 'pdb' (minus the quotes) at the prompt turns on
automatic invocation of the pdb debugger at uncaught exceptions. Then all
you need to do is run your scripts from within ipython (use the 'run'
command for that). Once you're done, you can call 'pdb' again to turn the
feature off ('pdb' is an on/off toggle).
This gives you pdb with the stack of your code 'live', which makes it quite
easy to debug problems. You can walk up and down the stack, print the
values of variables, run code and call functions on them, etc. You can't
resume execution, but it's still quite useful.
Note that similar functionality can be added to any python session, it's
just a matter of resetting sys.excepthook to pdb with the right mode. For
details (which I don't recall), see the ipython sources.
Cheers,
f.
More information about the Python-list
mailing list