(original) (raw)

On Tue, Nov 25, 2014 at 10:12 AM, Isaac Schwabacher <ischwabacher@wisc.edu> wrote:
On 11/25/14, Guido van Rossum wrote:
> On Tue, Nov 25, 2014 at 9:49 AM, Chris Angelico <ischwabacher@wisc.edu <rosuav@gmail.com')" target="1">rosuav@gmail.com> wrote:
\>
\> > On Wed, Nov 26, 2014 at 4:45 AM, Isaac Schwabacher
> > <python.org/\~guido(javascript:main.compose('new', 't=ischwabacher@wisc.edu>> wrote:
\> > > Yield can also raise StopIteration, if its thrown in. The current interaction of generator.throw(StopIteration) with yield from cant be emulated under the PEPs behavior, though its not clear that thats a problem.
> >
\> > Hrm. I have \*absolutely\* no idea when you would use that,

To close the innermost generator in a yield-from chain. No, I don't know why you'd want to do that, either.

For that purpose you should call the generator's close() method. This throws a GeneratorExit into the generator to give the generator a chance of cleanup (typically using try/finally). Various reasonable things happen if the generator misbehaves at this point -- if you want to learn what, read the code or experiment a bit on the command line (that's what I usually do).

--
--Guido van Rossum (python.org/\~guido)