[PyKDE] QWaitCondition seems to cause deadlock

Phil Thompson phil at riverbankcomputing.co.uk
Tue May 18 20:14:01 BST 2004


On Tuesday 18 May 2004 5:58 pm, 森田 慎一 wrote:
> Hi, this is shin.
> It's my first time to post to this ml.
>
> I'm a beginner of PyQt.
> PyQt is very exciting!!
> But I have a problem on my multi-thread script.
>
> This script uses Qt thread API, and uses QMutex and
> QWaitCondition to synchronize a GUI thread and a worker
> thread.
> When the worker thread calls QWaitCondition.wait(), GUI
> thread also stops running.
> It seems to be in deadlock state.
>
> The worker's code is as follows:
>
> def postAndWait(self)
>     mutex.lock()
>     QApplication::postEvent(receiver,
> QCustomEvent(QEvent.User))
>     # waits until GUI thread processes the posted event.
>     condition.wait(mutex) # <-- stops everything!!
>     mutex.unlock()
>
> GUI thread processes events as follows:
>
> def customEvent(self, event)
>     mutex.lock()
>     # do something ...
>     condition.wakeAll()
>     mutex.unlock()
>
> I've been at a loss for a few days.
> But today I found that Python Global Interpreter Lock
> needs to be released and reacquired around blocking
> operation according to Python C/API Reference Manual.
> And I also found that QWaitCondition::wait()  in
> qwaitcondition.sip has no annotation while
> QThread::sleep() has /ReleaseGIL/ annotation.
>
> I think that QWaitCondition::wait() must have /ReleaseGIL/
> annotation, is that right?

Reading the documentation, I think you are right. It looks like it's missing 
on QMutex.lock() as well. Tonight's snapshot should be fixed.

Thanks,
Phil




More information about the PyQt mailing list