Debugging a Python Program that Hangs

K

Kevin D. Smith

I have a fairly large python program that, when a certain combination
of options is used, hangs. I have no idea where it is hanging, so
simply putting in print statements to locate the spot would be quite
difficult. Unfortunately, ctrl-C'ing the program doesn't print a
traceback either. Looking through the python debugger documentation, I
don't see how to run a python program and interactively stopping it
while it is running. Is there a way to stop within a running python
program to see where it is getting hung up?
 
A

alex23

I have a fairly large python program that, when a certain combination
of options is used, hangs.  I have no idea where it is hanging, so
simply putting in print statements to locate the spot would be quite
difficult.  Unfortunately, ctrl-C'ing the program doesn't print a
traceback either.  Looking through the python debugger documentation, I
don't see how to run a python program and interactively stopping it
while it is running.  Is there a way to stop within a running python
program to see where it is getting hung up?

Hey Kevin, long time fan of your films! (I bet you get that a lot...)

The trace module might help you identify where it's getting caught up:

http://www.python.org/doc/2.5.2/lib/trace-cli.html
 
K

Kay Schluehr

I have a fairly large python program that, when a certain combination
of options is used, hangs.  I have no idea where it is hanging, so
simply putting in print statements to locate the spot would be quite
difficult.  Unfortunately, ctrl-C'ing the program doesn't print a
traceback either.  Looking through the python debugger documentation, I
don't see how to run a python program and interactively stopping it
while it is running.  Is there a way to stop within a running python
program to see where it is getting hung up?

You might approximate the critical location using exceptions instead
of prints. That's more costly of course because the program has to be
restarted more often but it will serve the same purpose.
 
R

Ross Ridge

Kevin D. Smith said:
I have a fairly large python program that, when a certain combination
of options is used, hangs. I have no idea where it is hanging, so
simply putting in print statements to locate the spot would be quite
difficult. Unfortunately, ctrl-C'ing the program doesn't print a
traceback either.

Have you tried catching the KeyboardInterrupt exception and printing
an exception? Something like:

try:
rest_of_program()
except KeyboardInterrupt:
traceback.print_exc()
raise

Ross Ridge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top