Suggested generator to add to threading module.
Andrae Muys
amuys at shortech.com.au
Thu Jan 15 23:58:43 EST 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