Stackless Python and Python 2.x
tim.one at home.com
Sun Sep 2 04:27:49 CEST 2001
> How is it possible to implement resumable generators without using
> coroutines, continuations, or something equivalent?
Have you read the PEP?
This flavor of generator is formally a semi-coroutine, and it's the
asymmetry that makes impementation easier; a PEP 255 generator can suspend
only to the routine that invoked it, and only to the point of invocation,
which implies that nothing more than the generator's local state needs to be
preserved between resumptions. In Python terms, since execution frames were
already heap-allocated, its not much of an exaggeration to say that the
primary trick to implementing generators was simply to refrain from
decrementing a frames refcount upon yielding.
BTW, the book Advanced Programming Language Design is available online:
and chapter 2 shows in excruciatingly detail how to implement CLU iterators
(also semi-coroutines) using almost-standard C, abusing the C stack via
More information about the Python-list