dropping into the debugger on an exception

Jon Perez jbperez808 at yahoo.com
Wed Jun 9 11:46:11 EDT 2004


Peter Hansen wrote:

> Just to be clear: you don't want this to happen all the time,
> you want it to happen only with a particular script, yet you
> don't want to modify that script at all?

Correct.  I don't even want it to happen all of the time
with that particular script (because I may eventually
deploy it for others to use who may be confused by
being dropped into pdb).  I can easily disable it by not
assigning info() to sys.excepthook.  But like I said, preferably,
I don't even want to add anything to the script source code.

> Would it be sufficient to have a local sitecustomize.py file
> in the directory where the script is, or do you have other
> scripts in that folder which you don't want to get the same
> treatment?

> What about a wrapper which you invoke instead of the script,
> which sets this up and then runs the real script using
> "import" and an appropriate direct call?

These are both acceptable to a certain extent, and frankly,
if these were the alternatives,  I will just stick to putting
info() in any script I intend to debug this way.

I was just wondering if there wasn't a cleaner/more intuitive
way which would be to just invoke the script from within pdb
and have pdb do the right thing (i.e. stay within itself) upon
an exception.

Can't one prevent pdb from exiting if an (unanticipated)
exception occurs in a script (or function) it invokes?

And secondly, how do you pass command-line arguments to a
script invoked from within pdb?  I'm not even sure how to
invoke a script proper like you would from a command line, all
the examples I see invoke specific functions within a script.

Not being able to accomplish simple things like this in a
straightforward manner is what's keeping me from wholeheartedly
embracing pdb.



More information about the Python-list mailing list