How to troubleshoot hanging script?

kj socyl at 987jk.com.invalid
Tue Aug 5 13:38:20 EDT 2008



Hi!  I have a Pythonoob question.

I have a script that hangs indefinitely at random times; the only
thing to do at this point is to kill it.

I'm looking for suggestions on how to troubleshoot and debug the
problem.

I'm not even sure of where exactly the script is hanging, though
I suspect it is right around when it tries to read from a pipe
(generated by popen).  (I arrived at this guess by putting print
statements all over the place, but I'm not sure this is a very
reliable way to pinpoint the error.)

So the first thing I'd like to do is find out exactly where the
script is hanging.  It would be nice if I could just hit Ctrl-C
(which sends SIGINT from the terminal) when the script is hanging,
to kill it and get a backtrace, but when this script hangs it
becomes unresponsive to Ctrl-C!  The only way to kill it is with
something like

  % pkill -KILL my_script.py

or even

  % pkill -TERM my_script.py

...or -ABRT or -QUIT.  I tried to exploit this by adding this to the
script:

import signal

def term_handler(signum, frame):
    raise KeyboardInterrupt

signal.signal(signal.SIGTERM, term_handler)

...but this did not help at all; in fact, after this addition, the script
no longer responded to pkill -TERM.

TIA!

Kynn
-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.



More information about the Python-list mailing list