By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,835 Members | 964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,835 IT Pros & Developers. It's quick & easy.

How to troubleshoot hanging script?

P: n/a
kj


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.
Aug 5 '08 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Hi,

Just a thought, I'm not sure it's the best way.
You can start an alarm just before the line you *think* it's wrong and
cancel it after that. If it's activated then you probably have
pinpointed the location. Have a look at the signals module
http://docs.python.org/lib/module-signal.html, the alarm function.

Hope it helps.

kj wrote:
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
Aug 6 '08 #2

P: n/a
kj a écrit :
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!
Pretty often, this kind of behaviour is related to a catch-all (or at
least a 'catch-too-much') except clause that doesn't re-raise.
wrt/ debugging, there's a command-line debugger named pdb in the stdlib.
Aug 6 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.