views:

100

answers:

3

I'm trying to debug a Python program and I inserted a classic 'import pdb;pdb.set_trace()' line in a function, just before a call which generates a stack trace. However that call seems to be ignored, i.e. nothing happens and I don't get a pdb prompt.

At that point of the program, there is only one active thread. No monkey patching of the pdb module was detected.

Any help on what could cause the call to set_trace to be ignored is welcome. Thanks.

Platform info: Debian squeeze + python 2.6.5

Code extract:

import threading
print threading.active_count()
import pdb
print pdb
pdb.set_trace()
print "*****"
root_resource.init_publisher() # before changing uid

output:

<lots of stuff>
1
<module 'pdb' from '/usr/lib/python2.6/pdb.pyc'>
*****
<stack trace in init_publisher>
A: 

You are probably not running that statement, either because:

  • the stacktrace is not where you thought it was
  • you inserted the set_trace call in a similar but wrong place
  • you are running a different .py file than the one you edited
  • you have your own local pdb.py file that is getting imported instead of the one from the stdlib
Paul McGuire
Nice try, but no: I've added some code in the original message, showing that this is not the case.
gurney alex
Are you piping stdin from something other than the interactive console?
Paul McGuire
+2  A: 

Perhaps you've got some tricky code that manipulates the trace function in a complicated way? Or are you using an accelerator like psyco?

Ned Batchelder
Through some very weird setup, it turns out one optional module in the application could not load a C extension (missing shared lib) and defaulted on a pure python implementation which used psyco (http://psyco.sf.net) to speed up things. Psyco does weird stuff with python frames, and this makes the python debugger very confused.
gurney alex
+1  A: 

This is going to waste the time of a number Python developers. Tonight I added myself to their ranks. I wish I had found this post before I spent 2 hours discovering a similar problem with a large library I am using. Subsequent Google searches hardly shed much light on the issue of pdb and pysco incompatability. The problem should be more visible to users starting out with pdb.

Deep within the guts of a library I was importing was a file which contained the following code:

try:
    import psyco
    psyco.bind(bdecode)
    psyco.bind(bencode)
except ImportError:
    pass

What a lovely gesture of the author, who obviously assumed no one using their code, and who had also installed psyco, would ever like to use a tool such as pdb to debug it ;-) Mind you, you could ask how were they mean't to know anyway?

Whilst exploring the problem I found that usage of:

import pdb; pdb.set_trace() 

after the import of psyco, is just passed over; for neither rythme nor reason. Very frustrating indeed.

The problem does not effect debugging with PyDev or, I presume, other more advanced debuggers, which is I guess why it falls outside the radar of initial Google searches.

landstatic