python threading

Cliff Wells logiplexsoftware at earthlink.net
Tue Apr 16 15:47:51 EDT 2002


On Tue, 16 Apr 2002 19:42:37 +0200
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...

I'm not too familiar with other GUI toolkits, but in wxPython it's possible to
generate a custom wxEvent that is put on the GUI's event queue and processed
like any other GUI event.  You can then create an event handler for that custom
event and safely do your updates there.  I've found this to be the simplest way
to interact with a GUI from a thread.  I'd be surprised if PyQt didn't support
something similar.

-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308





More information about the Python-list mailing list