[PyQt] Re: Embedding w/ multi-threaded Python

Phil Thompson phil at riverbankcomputing.com
Tue Mar 10 21:08:22 GMT 2009


On Tue, 10 Mar 2009 10:30:04 -1000, McKay Davis <mckay.cpp at gmail.com>
wrote:
> After no response, maybe more specifics with our Multi-Threaded Python
> w/ PyQt problem would help:
> 
> In the main thread, we do:
> 
> PyEval_InitThreads(); // acquires the lock
> PyInitialize();
> // other init stuff
> PyThread_release_lock()
> 
> …and in each new Python thread we do:
> Py_NewInterpreter()
>> PyThreads_release_lock()
> 
> We call release()/acquire() blocks whenever the python script does a
> blocking operation.  A specific example of a lockup with PyQT is
> running examples/tutorial/t8.pyw.  We basically:
> 
> PyThreads_acquire_lock()
> <run example script>
> PyThreads_release_lock()
> 
> When a slot is invoked as a result of the slider being moved we get a
> deadlock.  This happens when sip_ProtectVirt_languageChange calls
> PyThreads_release_lock() on an already released lock.  If we don’t
> release the lock after the main thread PyQT script code runs, then the
> script runs fine – but our other python script threads will be starved
> out.
> 
> Anybody have any ideas on how to resolve this deadlock?

PyQt uses the PyGILState_* functions. These aren't supported with multiple
interpreters - see the docs for Py_NewInterpreter().

Phil


More information about the PyQt mailing list