[Python-ideas] Revised**5 PEP on yield-from

Jim Jewett jimjjewett at gmail.com
Mon Mar 2 04:05:16 CET 2009


On 3/1/09, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Jacob Holm wrote:

>> A
>>  \
>>    R --- (whatever R is waiting for)
>>  /
>> B

>... normally you'd create a fresh iterator
> for each yield-from that you want to do. So A and B would really
> be yielding from different iterators, even if they were both
> iterating over the same underlying object.

I think the problem might come up with objects that are using the
iterator protocol destructively.  For example, imagine A and B as
worker threads, and R as a work queue.

> If you did try to share iterators between yield-froms like that,
>... something is
> going to get an exception due to trying to resume an exhausted
> iterator.

I would expect that to be interpreted as a StopIteration and handled
gracefully. If that doesn't seem reasonable, then I wonder if the
whole protocol is still too fragile.

-jJ



More information about the Python-ideas mailing list