pdb in python2.5
rocky at panix.com
Thu Jan 25 14:08:39 CET 2007
"Rotem" <vmalloc at gmail.com> writes:
> 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,
> from __future__ import with_statement
> import threading
> def f():
> l = threading.Lock()
> with l:
> print "hello"
> raise Exception("error")
> print "world"
> import pdb
> This fails because pdb.pm() attempts to access sys.last_traceback which
> is not assigned.
Recent releases of pydb (http://bashdb.sf.net/pydb) don't suffer this
problem. (But see below.)
> Yields the following:
> > test.py(9)f()
> -> print "world"
> 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?
Yes, this seems to be a bug in pdb. It is using the traceback's f_line
instance variable rather than the tb_lineno instance variable. I guess
these two values are usually the same. In fact, I haven't been able to
come up with a Python 2.4 situtation where they are different. (If
someone can, I'd appreciate it if you'd send me a small example so I
can put it in the pydb regression tests.) Even in 2.5, it's kind of
hard to get a case where they are different. If I remove the "with",
the problem goes away.
It was also bug in pydb, but I've just committed in CVS the fix for
> is pdb broken?
Best as I can tell pdb isn't all that well maintained. (Had it been, I
probably wouldn't have devoted the time to pydb that I have been.)
> I get similar results for larger/more complex pieces of code.
> Thanks in advance,
More information about the Python-list