send() to a generator in a "for" loop with continue(val)??

Michele Simionato michele.simionato at
Sun Apr 19 08:09:50 CEST 2009

On Apr 18, 5:19 pm, a... at (Aahz) wrote:
> Okay, I'm curious, is the argument that you shouldn't use generators for
> coroutines or something else?

Yes, there is certainly the confusion between generators
and coroutines (the ones David Beazley warns about).

At first, I was a supported of yield
expressions. After they entered in Python 2.5 and I
had occasion to play with them in practice, I realized that we
did not gain much from them. In an ideal world (one
that would never happen) I would like to remove
yield expressions and keep generators simple. OTOH,
I would like a simple coroutine library in the standard
library, with a trampoline and a scheduler. Coroutines,
however, would be implemented as simple objects with
a .send and .recv method, not by abusing yield expression.
May be we would lose a tot percent of performance, but
that should not be a concern for a Pythonista.
I dunno if Peter Otten thinks the same or has other
ideas, but this is what I have in mind. The important
addition in Python 2.5 was the introduction of
GeneratorExit and the ability to use yield inside
try .. finally blocks. This was a needed language level change.
Coroutines instead could have been implemented as
a library, without requiring any language change.

But the point is moot, anyway, and certainly I did not
think of it at the time yield expressions were introduced.

             Michele Simionato

More information about the Python-list mailing list