[PyQt] Threads with PyQt. Qt's or Python's?

Christoph Burgmer chrislb at gmx.de
Tue Jan 20 04:08:58 GMT 2009


Am Tuesday, 20. January 2009 schrieb Giovanni Bajo:
> On 1/19/2009 4:36 PM, Christoph Burgmer wrote:
[...]
> > I am doing a
> >
> > QCoreApplication.postEvent()
> >
> > out of "run()" from a "threading.Thread" class without any problems.
>
> That's only because you are lucky. It's not something that's officially
> supported and I have spent days debugging random crashes that turned out
> being Qt accesses from threads allocated by Python.
>
> I suggest you to fix your code.

We have an unlucky situation here, Qt documents neither say that mixing 
threading libraries is ok, nor does it say it could lead to clashes.

Now guessing won't help, but I'll do it anyway:
QCoreApplication::postEvent() is "thread-safe" and thus has the highest safety 
level one could whish for in the Qt threading system. It works by adding the 
event to the event queue and returning immediatelly.
It's the main event loop that then takes over.

Now from that I would assume the only clashes could occur when fiddeling with 
the event queue. Instead of assuming some magic done in every thread I rather 
believe that synchronisation is done in the local method, postEvent(). Now 
things going wrong would mean that synchronisation there does depend on the 
threads all adhering to the same special protocol, something that IMHO is not 
needed to complete this task.

Anyway, if somebody should have a bit more indepth knowledge on that, please 
step up.

Christoph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090120/56700f65/attachment.html


More information about the PyQt mailing list