Suggested generator to add to threading module.
amuys at shortech.com.au
Mon Jan 19 03:08:29 CET 2004
aahz at pythoncraft.com (Aahz) wrote in message news:<bu998t$o62$1 at panix1.panix.com>...
> In article <7934d084.0401152058.164a240c at posting.google.com>,
> Andrae Muys <amuys at shortech.com.au> wrote:
> >Found myself needing serialised access to a shared generator from
> >multiple threads. Came up with the following
> >def serialise(gen):
> > lock = threading.Lock()
> > while 1:
> > lock.acquire()
> > try:
> > next = gen.next()
> > finally:
> > lock.release()
> > yield next
> I'm not sure this is generic enough to go in the standard library.
> Usually, I'd recommend that someone wanting this functionality consider
> other options in addition to this (such as using Queue.Queue()).
I'm curious to know how a Queue.Queue() provides the same
functionality? I have always considered a Queue.Queue() to be an
inter-thread communcation primitive. serialise() (at least the
corrected version discussed later in this thread) is strictly a
More information about the Python-list