[Python-ideas] Yield-From: Finalization guarantees
greg.ewing at canterbury.ac.nz
Wed Mar 25 23:02:55 CET 2009
Nick Coghlan wrote:
> That is, I now believe the 'normal' case for 'yield from' should be
> modelled on basic iteration, which means no implicit finalisation.
> Now, keep in mind that in parallel with this I am now saying that *all*
> exceptions, *including GeneratorExit* should be passed down to the
> subiterator if it has a throw() method.
But those two things are contradictory. In a refcounting
Python implementation, dropping the last reference to the
delegating generator will cause it to close() itself,
thus throwing a GeneratorExit into the subiterator. If
other references to the subiterator still exist, this
means it gets prematurely finalized.
> With an expansion of that form, you can easily make arbitrary iterators
> (including generators) shareable by wrapping them in an iterator with no
> throw or send methods:
But if you need explicit wrappers to prevent finalization,
then you hardly have "no implicit finalization". So I'm a
bit confused about what behaviour you're really asking for.
More information about the Python-ideas