On 15.04.17 01:42, Greg Ewing wrote:
Serhiy Storchaka wrote:
but should not affect performance since locking is used only when you
faced with a generator running in other thread.
I don't think that's true, because the first thread to use a
generator has to lock it as well. And even if there is only
one thread in existence when __next__ is called, another one
could be created before it finishes and try to use the
generator.
The first thread just sets the running flag (as in current code). Due to
GIL this doesn't need additional synchronization. Other threads check
this flag and sleep rather than raising an exception. After finishing
the generator the first thread checks if there are other threads
awaiting and awake a one of them.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/