Gui thread and async jobs.

Phil Thompson phil at riverbankcomputing.co.uk
Wed May 9 11:19:49 EDT 2007


On Wednesday 09 May 2007 3:58 pm, Grant Edwards wrote:
> On 2007-05-08, king kikapu <aboudouvas at panafonet.gr> wrote:
> > Hi, i am reading the book "Python Cookbook, 2nd edition" and i
> > encountered a very handy recipe, the one that is called
> > "Combining GUIs and Asynchronous I/O with Threads"
> >
> > It is talking about retain a main GUI thread, doing async work
> > with worker threads and have both talk through a Queue object
> > to dispatch their messages, so the main (GUI) thread remain
> > responsive. It has a very good example by using Tkinter and Qt
> > that is indeed working. The only point that make me wonder is
> > that the QUI thread has to use some polling to check for
> > messages in the Queue.
>
> It sounds to me like Qt is missing some rather important
> features and/or convenience functions.  In other toolkits (e.g.
> wxPython), invoking GUI methods/functions from non-GUI threads
> is trivial and involves no polling by the GUI thread.
>
> For example, if in a wxPython application you wanted to call
> someGUIobject.method(foo,bar) from a non-GUI thread you just do
> this:
>
>    wx.CallAfter(someGUIobject.method,foo,bar)
>
> If you look under the covers there is a queue involved, but
> it's nothing the user has to poll or worry about.

In Qt it's all part of the signal/slot mechanism which works across threads. 
Surprise, surprise, under the covers there is a queue involved.

Phil



More information about the Python-list mailing list