python threading

Justin Sheehy justin at iago.org
Tue Apr 16 13:35:51 EDT 2002


Alex Martelli <aleax at aleax.it> writes:

> Right!  Queue is THE way to go.  Now, life would be perfect if threads
> generally devoted to such tasks as GUI's or networking didn't have to
> _periodically poll_ to check if there's something new on the Queue for
> them (with a timeout in select, a Tkinter .after callback, a QTimer
> instance in Qt, etc etc).  I.e., if Queue had some way to "jig" the
> waiting thread out of its waiting state, when new stuff is posted to
> the Queue, in such a way that the thread knows it must check its incoming 
> Queue. 

Unless I'm misunderstanding the question, threading.Event is the answer.

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.

-Justin

 






More information about the Python-list mailing list