-2

There is a high level logic error deep within my Python script, and pdb doesn't help to debug it. Is there any other way to see what is being executed after I run my script?

NOTE: Using pdb is too slow and inconvenient - I wish I could grep over all cases when my function is executed, instead of inspecting manually each and every call, set/unset breakpoints. The state is lost when I exit pdb and its user interface is more confusing than helpful - requires docs at hand.

UPDATE: made it clear that pdb is not an option, so the most popular Python debugging tips can not be applied

Community
  • 1
  • 1
anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140

3 Answers3

1

I would recommend using pdb. You can use

import pdb

at the top of your script, and then add the line

pdb.set_trace()

somewhere in the code where you want to trace the problem. When the script gets to that line, you will have an interactive console where you can check variable values, run your own checks, and see what is going on. You can use n to execute the next line, or c to continue to the next occurrence of set_trace(). Full documentation is here: http://docs.python.org/2/library/pdb.html.

Let me know if you have any specific questions!

Jason B
  • 7,097
  • 8
  • 38
  • 49
  • Interactive session doesn't really help in my case - it is not quick and I can not grep over the lines and see what was already executed. – anatoly techtonik Jan 01 '14 at 14:24
0

No, there's no magic formula.

My best suggestion is to get a good IDE with a debugger, like JetBrains' PyCharm, and step through your code to see where you went wrong.

Most of the time these situations happen because you make assumptions about behavior that aren't true. Get a debugger, step through, and check your assumptions.

duffymo
  • 305,152
  • 44
  • 369
  • 561
0

I found a way to do this using excellent trace module that comes with Python.

An example how to troubleshoot module installation problem:

python -m trace -t setup.py install > execution.log

This will dump all source line of setup.py install execution to execution.log. I find this more useful than pdb, because usability of pdb command line interface is very poor.

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140