Multiple threads in a GUI app (wxPython), communication between worker thread and app?

Paul Rubin http
Mon May 23 23:04:03 EDT 2005


Jp Calderone <exarkun at divmod.com> writes:
> >Secondly, I don't know about wxPython, but in tkinter you have to
> >resort to a kludge in order for the gui thread to handle gui events
> >and also notice stuff on a queue.  There's a tkinter command to run
> >some function after a specified time (say 50 msec).  So you'd set that
> >timeout to check the queue and restart the timer, which means the gui
> >would check 20x a second for updates from the worker threads.  When it
> >got such an update, it would create a new window or whatever.
> 
> You can do better than this.  Tkinter has an after_idle function,
> which lets you post an event to the Tkinter thread _immediately_.
> This is basically the Queue "put" operation.

I don't understand how this is supposed to work.  Can you explain a
little further?  As far as I can tell, it's not documented as safe to
call w.after_idle from another thread.  Is it actually safe according
to how the code is written?  Otherwise, the only way I can see is
to use a queue (or other synchronization object) and let the tkinter
thread check the queue periodically itself.

> > Python thread support seems to have been something of an
> > afterthought and there's a lot of weirdness like this to deal with.
>   I'm not sure what you see as weird about this.

Having to deal with this timeout stuff instead of having a documented
thread-safe way to add events to a tkinter event queue.



More information about the Python-list mailing list