[Python-Dev] deadlock problem

Harri Pasanen harri.pasanen@trema.com
Thu, 31 Jul 2003 11:53:39 +0200


Hi,

I'm having a deadlock on import in my embedded python 2.3rc2, on 
Win2000, built with Visual C++ 7.1.

Having spent a fair amount of time going through the code, and 
various threads, it is still not clear to me if I'm hitting the 
problem described in the thread: 
http://mail.python.org/pipermail/python-dev/2003-February/033436.html 
or if I'm triggering it because of something else alltogether, as 
I'm only seeing the problem on Win2000, on Linux it works fine.

Basically my code does this in one C level thread:

    PyGILState_STATE _tstate = PyGILState_Ensure ();
    PyObject* usermod = PyImport_ImportModule ("echo");

Where echo.py is just:

print "ECHO"
import time
time.sleep(1)
print "DONE"

It never prints out "DONE".  If I take away the sleep(), it 
finishes, printing DONE.

running with THREADDEBUG=15, I'm getting the output below, and the 
last two lines leave me utterly puzzled, as if something would be 
quite wrong on my machine (Win2000 under VmWare Linux host).
Why could the same thread be unable reacquire a lock it just held?

PyThread_init_thread called
1084: PyThread_allocate_lock() -> 01647578
1084: PyThread_acquire_lock(01647578, 1) called
1084: PyThread_acquire_lock(01647578, 1) -> 1
1084: PyThread_release_lock(01647578) called
1084: PyThread_acquire_lock(01647578, 1) called
1084: PyThread_acquire_lock(01647578, 1) -> 1
1084: PyThread_release_lock(01647578) called
PyThread_allocate_lock called
1084: PyThread_allocate_lock() -> 0164A280
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
PyThread_allocate_lock called
1084: PyThread_allocate_lock() -> 0256DD40
1084: PyThread_acquire_lock(0256DD40, 1) called
1084: PyThread_acquire_lock(0256DD40, 1) -> 1
1084: PyThread_release_lock(0256DD40) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
PyThread_allocate_lock called
1084: PyThread_allocate_lock() -> 01648DA8
1084: PyThread_acquire_lock(01648DA8, 1) called
1084: PyThread_acquire_lock(01648DA8, 1) -> 1
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_release_lock(01648DA8) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
1084: PyThread_release_lock(0164A280) called
1084: PyThread_acquire_lock(0164A280, 0) called
1084: PyThread_acquire_lock(0164A280, 0) -> 1
ECHO
1084: PyThread_release_lock(01648DA8) called
1084: PyThread_acquire_lock(01648DA8, 1) called

Harri