Suggested generator to add to threading module.

Andrae Muys amuys at shortech.com.au
Fri Jan 16 05:58:43 CET 2004


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 considered suggesting it for itertools, but really it's thread
specific so I am suggesting it for the threading module.

Andrae Muys



More information about the Python-list mailing list