PEP 255: Simple Generators

Tim Peters tim.one at home.com
Fri Jun 15 16:45:33 EDT 2001


[Robin Becker]
> Who owns the generator state is it the caller or the callee?

Neither:  it's part of the generator-iterator.  Under the covers, it's
simply the callee's activation record ("frame"); the primary trick to
implementing generators is simply to refrain from decrementing the frame's
refcount when leaving the function.  The generator-iterator holds a
reference to the frame instead, and the frame will be discarded as a matter
of course when the iterator becomes trash.





More information about the Python-list mailing list