Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > dropping into pdb on an exception

Reply
Thread Tools

dropping into pdb on an exception

 
 
Jon Perez
Guest
Posts: n/a
 
      06-09-2004
How do you set up pdb such that you will automatically
get dropped into its prompt if an unanticipated exception
occurs in a script you are using?

ASPN Python cookbook gives you the following method
which you can add to your script and hook into sys.excepthook.
But is there a way to do it without adding stuff to your
script? (It's okay if this means having to invoke the script
from within pdb, but #1, I don't know how to get it stay inside
pdb in the case of an /unanticipated/ exception. And #2, I
don't know how to pass [the equivalent of] command-line
arguments to a script invoked from within pdb.)



def info(type, value, tb):
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(type, value, tb)
else:
import traceback, pdb
# we are NOT in interactive mode, print the exception...
traceback.print_exception(type, value, tb)
print
# ...then start the debugger in post-mortem mode.
pdb.pm()

sys.excepthook = info

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using pdb and catching exception Amit Gupta Python 5 12-06-2007 11:07 PM
Palm::PDB: How to compose a PDB? Josef Moellers Perl Misc 0 08-16-2007 02:29 PM
ADSL Dropping But not Dropping!! Chris Bales Computer Support 9 08-29-2004 06:25 PM
dropping into the debugger on an exception Jon Perez Python 13 06-14-2004 11:57 AM
staying inside pdb.py upon an exception in a program run via it Jon Perez Python 0 06-06-2004 09:24 PM



Advertisments