Suggested generator to add to threading module.
Ype Kingma
ykingma at accessforall.nl
Fri Jan 16 14:42:36 EST 2004
Andrae Muys 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
Is there any reason why the lock is not shared among threads?
>From the looks of this, it doesn't synchronize anything
between different threads. Am I missing something?
Kind regards,
Ype
email at xs4all.nl
More information about the Python-list
mailing list