[Python-Dev] help debugging thread deadlocks

Russ Cox rsc@plan9.bell-labs.com
Fri, 1 Mar 2002 22:52:42 -0500


If this should be in python-list, say so and I'll move,
but python-dev seemed a better match.

I've got a python program that's hanging in
PyThread_acquire_lock called from fast_cfunction,
which I assume means the python program itself is
calling the acquire method on a python-allocated
(as opposed to C-allocated) lock.  There are two
threads and both are hung trying to acquire different locks.
Unfortunately that's all I can tell from the
stack trace.  My python program allocates three
locks using threading.RLock, and I can't find any
other python code (in the standard modules), but
the locks that are hanging are not those three locks.
I looked in the standard module library code and can't
find any that allocate locks.  There are some locks
allocated in the C interpreter, of course, but I don't
see how those would be acquirable from python code.

Is there some function I can call from within 
acquire_lock or allocate_lock (from C) to dump
a python stack trace to stdout or stderr?

Thanks.
Russ