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>
pdb. set_trace(*, header=None) Enter the debugger at the calling stack frame. This is useful to hard-code a breakpoint at a given point in a program, even if the code is not otherwise being debugged (e.g. when an assertion fails). If given, header is printed to the console just before debugging begins.
To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally, and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().
To start execution, you use the continue or c command. If the program executes successfully, you will be taken back to the (Pdb) prompt where you can restart the execution again. At this point, you can use quit / q or Ctrl+D to exit the debugger.
Pdb is a powerful tool for finding syntax errors, spelling mistakes, missing code, and other issues in your Python code.
You are probably not running that statement, either because:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With