python threading

Geoffrey Talvola gtalvola at nameconnector.com
Tue Apr 16 14:39:52 EDT 2002


Alex Martelli wrote:
> On Tuesday 16 April 2002 07:35 pm, Justin Sheehy wrote:
> 	...
> > I've wrapped Queues with Events before, and it makes things a little
> > nicer.  It is quite straightforward to make a Queue that exposes a
> > get method that will simply block until an Event is set by another
> > thread or an optional timeout has elapsed.
> >
> > It doesn't solve the whole problem, but waiting on an Event is much
> > nicer than a get/sleep loop.
> 
> Yes, but a GUI thread can't do that either -- nor can a network one;
> they must be ready for user-input events and netword-data-arriving
> events too.  The problem is how to seamlessly merge waiting for
> THOSE kinds of things and for Python-thread-stuff kinds...
> 

Don't most GUI toolkits have some way to post an event to the main GUI
thread's event loop from another thread?  wxPython has wxPostEvent() which
does this.

So you could write a wrapper class around Queue that posts a "wakeup" event
to the main GUI thread after an item is added to the queue.  The event
handler for the "wakeup" event would process whatever items had been added
to the Queue and then return control to the event loop.

- Geoff





More information about the Python-list mailing list