Dumping the state of a deadlocked process

Ziga Seilnacht ziga.seilnacht at gmail.com
Sat Oct 7 11:49:21 CEST 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.
>
> 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?

Check out the sys._current_frames() function, new in Python 2.5:
http://docs.python.org/lib/module-sys.html#l2h-5122

Hope this helps,
Ziga




More information about the Python-list mailing list