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
-- http://mail.python.org/mailman/listinfo/python-list