feature proposal, debug on exception

P

Paul Rubin

There's an occasional question here about how to get python to launch
pdb on encountering an uncaught exception. The answer is to look in
some ASPN recipe and do some weird magic. I guess that works, but
it's another thing to remember or keep looking up when the occasion
arises (some program crashes unexpectedly). I find myself manually
adding tracing instead, finding out that I did it wrong and having to
re-launch a long-running program, etc.

I'd like to propose that debug-on-exception be made into a standard
feature that is easy to enable, e.g. with a command line option
or with a simple pdb call immediately after the import:

import pdb
pdb.debug_on_exception(True)
...

Would there be big obstacles to this? It would have saved me
considerable hassle on a number of occasions. I'm constantly
processing large data sets that will munch along happily for hours and
hours before hitting some unanticipated condition in the data, and it
would be great to trap immediately rather than have to analyze the
resulting stack dump and restart.
 
S

Simon Forman

There's an occasional question here about how to get python to launch
pdb on encountering an uncaught exception. The answer is to look in
some ASPN recipe and do some weird magic. I guess that works, but
it's another thing to remember or keep looking up when the occasion
arises (some program crashes unexpectedly). I find myself manually
adding tracing instead, finding out that I did it wrong and having to
re-launch a long-running program, etc.

I'd like to propose that debug-on-exception be made into a standard
feature that is easy to enable, e.g. with a command line option
or with a simple pdb call immediately after the import:

import pdb
pdb.debug_on_exception(True)
...

Would there be big obstacles to this? It would have saved me
considerable hassle on a number of occasions. I'm constantly
processing large data sets that will munch along happily for hours and
hours before hitting some unanticipated condition in the data, and it
would be great to trap immediately rather than have to analyze the
resulting stack dump and restart.


This is not exactly an answer to your proposal, I know, but FWIW
Ipython has exactly this capability.

Regards,
~S
 
A

alex23

I'd like to propose that debug-on-exception be made into a standard
feature that is easy to enable, e.g. with a command line option
or with a simple pdb call immediately after the import:

Forgive me if I've missed your point, but it seems you can already do
this:

pdb.py can also be invoked as a script to debug other scripts.
For example:

python -m pdb myscript.py

When invoked as a script, pdb will automatically enter post-mortem
debugging if the program being debugged exits abnormally. After
post-mortem debugging (or after normal exit of the program), pdb
will restart the program. Automatic restarting preserves pdb's
state (such as breakpoints) and in most cases is more useful than
quitting the debugger upon program's exit. New in version 2.4:
Restarting post-mortem behavior added.

http://docs.python.org/lib/module-pdb.html
 
V

Ville M. Vainio

Simon Forman said:
This is not exactly an answer to your proposal, I know, but FWIW
Ipython has exactly this capability.

Yes.

When you %run a scripts and get exception, you can launch post-mortem
pdb on it by typing %debug.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top