Dumping the state of a deadlocked process

Hendrik van Rooyen mail at microcorp.co.za
Sat Oct 7 03:34:43 EDT 2006


 <andre.naess at gmail.com> wrote:
> Hi all
>
> I'm currently having some issues with a process getting deadlocked. The
> problem is that the only way I can seem to find information about where
> it deadlocks is by making a wild guess, insert a pdb.set_trace() before
> this point, and then step until it locks up, hoping that I've guessed
> right.
>
> The frustrating part is that most of the time my guesses are wrong.

Welcome to the wonderful world of crash and burn....

>
> It would be really nice if I could send the python process some signal
> which would cause it to print the current stacktrace and exit
> immediately. That way I would quickly be able to pinpoint where in the
> code the deadlock happens. Java has a somewhat similar feature where
> you can send a running VM process a SIGQUIT, to which it will respond
> by dumping all current threads and lots of other information on stdout.
>
> Is this possible somehow?

Have you tried to sprinkle your code with print statements of the "We get here
No: 7" kind - you can get quite a good idea of what is going on if you do, and
if there are threads running - the results are often surprisingly insightful...

- Hendrik




More information about the Python-list mailing list