pdb in python2.5

Rotem vmalloc at gmail.com
Thu Jan 25 04:31:26 EST 2007


Hi,

Maybe I'm repeating a previous post (please correct me if I am).

I've tried the following code in python 2.5 (r25:51908, Oct  6 2006,
15:22:41)
example:

from __future__ import with_statement
import threading

def f():
    l = threading.Lock()
    with l:
        print "hello"
        raise Exception("error")
        print "world"

try:
    f()
except:
   import pdb
   pdb.pm()

This fails because pdb.pm() attempts to access sys.last_traceback which
is not assigned.
Trying:
pdb.post_mortem(sys.exc_traceback)

Yields the following:
> test.py(9)f()
-> print "world"
(Pdb)

the 'w' command yields a similar output, which implies that the
exception was thrown from the wrong line.
the traceback module is better, yielding correct results (displays line
8 instead of 9).

Has anyone encountered this behavior? is pdb broken?
I get similar results for larger/more complex pieces of code.

Thanks in advance,

Rotem




More information about the Python-list mailing list