dropping into the debugger on an exception
cliechti at gmx.net
Thu Jun 10 00:47:42 CEST 2004
Jon Perez <jbperez808 at yahoo.com> wrote in news:2iovgrFq6taqU1 at uni-
> Thomas Heller 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?
>> I also don't understand *why* he wants to have it that way.
> Just in case you missed the answer I gave earlier...
> I don't even want this behaviour all the time with the same
> script because end-users will be confused if they get dropped
> into pdb. Believe me, you don't want to explain what pdb is
> to people who have a hard time even navigating via the
> command prompt!
> The best situation would be to be able to invoke this behaviour
> only when I want it (i.e. during coding/debugging) and not have
> to change anything (including sitecustomize.py) when I don't
> want it around (the same machine might be used by both the
> developer and the end-user).
i usualy use something like that:
if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser()
action="store_true", dest="debug", default=False,
help="enable debug outputs")
(options, args) = parser.parse_args()
except Exception, msg:
#raise #i usualy use that
pdb.pm() #that's what you want
sys.stderr.write("%s: %s\n" % (msg.__class__.__name__, msg))
that way, adding a -d on the command line will enable more log messages and
full tracebacks (or pdb). you could of also use a separate option for pdb
or only enable it if multiple -ddd are given (debug level increased)
Chris <cliechti at gmx.net>
More information about the Python-list