Suggested generator to add to threading module.

Ype Kingma ykingma at
Fri Jan 16 20:42:36 CET 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 =
>     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,

email at

More information about the Python-list mailing list