14

I'm trying to help debug a python script that is causing python (2.7) itself to crashes.

  • The script logs some info to a file and it ends at a different stop on each run, or at least what it writes out is at a different spot.
  • The script already have a try\catch's.
  • The script has worked previously without errors
  • This is on Window 2008 servers, with a fair bit of RAM and when run not much CPU usage.

So my question:

  • Are there tools or techniques that could help?
    • I see that there is a pdb module I could import but not sure if that would help this issue.
  • When a py script crashes python itself how would you debug that?

GB

Gern Blanston
  • 42,482
  • 19
  • 50
  • 64
  • Hardware problem? Some obscure race condition because you are using unsafe multithreaded code? Corrupted Python installation? Corrupted external library? If it always crashes at different locations, it can be anything ... – Bas Swinckels Sep 05 '14 at 06:49

1 Answers1

21

So there are no exceptions in the log? It just exits randomly at different spots?

To see every statement as it's executed, use the trace module:

python -u -m trace -t program.py

To run the program in the debugger, use pdb:

python -m pdb program.py

With those two you should be able to see if it's something within the program causing it to exit. If you don't see any evidence or pattern then it could be something outside of the program causing it to die.

On Linux I would also try running the program with strace and watching for the OOM killer or segfaults. Not sure what similar steps would be in Windows, Windows doesn't have an OOM killer.

Amir
  • 10,600
  • 9
  • 48
  • 75
Steven Kryskalla
  • 14,179
  • 2
  • 40
  • 42
  • 1
    I'd recommend swapping *pdb* with [PuDB](https://pypi.python.org/pypi/pudb). It's a nice hybrid between pure console debugger and a more IDE-like debugger, all within the console environment. On *Windows*, for memory, it'd probably be something like **Resource Monitor** or perhaps the more advanced [Process Monitor](http://technet.microsoft.com/en-us/sysinternals/bb896645). – khampson Sep 06 '14 at 00:26