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

Giovanni Bajo rasky at develer.com
Mon Jan 19 17:12:35 GMT 2009


On 1/19/2009 4:36 PM, Christoph Burgmer wrote:
> Am Monday, 19. January 2009 schrieb Giovanni Bajo:
> 
>  > On 1/19/2009 3:13 PM, eliben wrote:
> 
>  > > I've seen various references to this issue before, but nothing to fully
> 
>  > > address it as I'd expect.
> 
>  > >
> 
>  > > Can you comment on the pros and cons of using QThread vs Python's 
> threads
> 
>  > > with PyQt?
> 
>  > >
> 
>  > > I'll begin: on the surface, Python's threads make more sense because
> 
>  > > they're Qt independent and can be ported between apps that don't
> 
>  > > necessarily depend on Qt (for example a web version of a GUI app). The
> 
>  > > Python thread API is powerful enough for all uses, it seems.
> 
>  > >
> 
>  > > However, there are concerns. Perhaps QThreads are more efficient? Or
> 
>  > > maybe more tightly integrated with the other parts of PyQt, so it's
> 
>  > > easier to use them?
> 
>  >
> 
>  > It's mostly the same. The main difference is that QThreads are better
> 
>  > integrated with Qt (asynchrnous signals/slots, event loop, etc.). Also,
> 
>  > you can't use Qt from a Python thread (you can't for instance post event
> 
>  > to the main thread through QApplication.postEvent): you need a QThread
> 
>  > for that to work.
> 
> 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.
-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com


More information about the PyQt mailing list