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
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
Comment