classification
Title: slightly easier way to debug from the exception handler
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: facundobatista Nosy List: bob.ippolito, facundobatista, leorochael
Priority: normal Keywords:

Created on 2005-01-20 22:06 by leorochael, last changed 2008-03-08 16:51 by facundobatista. This issue is now closed.

Messages (5)
msg54351 - (view) Author: Leonardo Rochael Almeida (leorochael) Date: 2005-01-20 22:06
When interactively developing/debugging a program it'd
be nice if we could throw the user into the pdb prompt
straight from the exception handler.

Currently, pdb.pm() only works outside of the exception
handler, after "sys.last_traceback" has already been
set, which doesn't happen inside the "except:" clause.
The alternative is to use:

 try:
   something...
 except:
   import sys, pdb
   pdb.post_mortem(sys.exc_info()[2])

I propose, as a convenience to the programmer, that the
first parameter to pdb.post_mortem() be made optional,
defaulting to None. In this case, it'd automatically
use the value of sys.exc_info()[2] in place of it's
otherwise mandatory first parameter. The example above
would be reduced to:

 try:
   something...
 except:
   import pdb;pdb.post_mortem()

alternatively, we could make it so that if
"sys.last_traceback" is not set "pdb.pm()" would pick
up sys.exc_info()[2] instead...
msg54352 - (view) Author: Bob Ippolito (bob.ippolito) * (Python committer) Date: 2005-01-20 22:51
Logged In: YES 
user_id=139309

Why put this in pdb.post_mortem() if we can just put it in pdb.pm()?  
pdb.pm() seems to already be for this purpose (except it currently only 
works from the interactive interpreter as you mention).
msg54353 - (view) Author: Leonardo Rochael Almeida (leorochael) Date: 2005-01-21 13:20
Logged In: YES 
user_id=200267

I don't have any particular reason to prefer post_mortem()
to pm().

The knowledgeable Python maintainers surely are better
equiped than I am to know if pm() looking beyond
sys.last_traceback is a worse break of assumptions than
post_mortem() having it's only parameter being optional or
the other way around :-)
msg63062 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-02-27 03:14
If there's no objections, I'd make the traceback parameter optional in
the post_mortem method, making it default to sys.exc_info()[2].

Thanks!
msg63404 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-03-08 16:51
Added this functionality in r61312.
History
Date User Action Args
2008-03-08 16:51:10facundobatistasetstatus: open -> closed
resolution: accepted
messages: + msg63404
2008-02-27 03:14:01facundobatistasetassignee: facundobatista
messages: + msg63062
nosy: + facundobatista
2005-01-20 22:06:51leorochaelcreate