Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug python script that is crashing python

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

like image 961
Gern Blanston Avatar asked Sep 05 '14 05:09

Gern Blanston


People also ask

How do you debug Python code in Python?

If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.

Is there a debug mode for Python?

Python has a built-in debugger called pdb . It's a simple utility with a command line interface that does the main job. It has all the debugger features you'll need, but if you're looking to pimp it up a little, you can extend it using ipdb, which will provide the debugger with features from IPython.

What is Python crash?

crash-python is a semantic debugger for the Linux kernel. It is meant to feel familiar for users of the classic crash debugger but allows much more powerful symbolic access to crash dumps as well as enabling an API for writing ad-hoc extensions, commands, and analysis scripts. $ pycrash vmlinux-4.12. 14-150.14-default.


1 Answers

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.

like image 162
Steven Kryskalla Avatar answered Sep 27 '22 17:09

Steven Kryskalla