[Python-ideas] A send() built-in function to drive coroutines

Luciano Ramalho luciano at ramalho.org
Mon Feb 23 20:10:15 CET 2015


On Mon, Feb 23, 2015 at 12:55 PM, Ron Adam <ron3200 at gmail.com> wrote:
> When using coroutines, they are generally run by a co-routine framework.
> That is how they become "CO"-routines rather than just generators that you
> can send values to.  Co-routines generally use the yield to pause/continue
> and to communicate to the framework, and not to get and receive data.  In
> most case I've seen co-routines look and work very much like functions
> except they have yield put in places so they cooperate with the frame work
> that is running them.  That frame work handles the starting co-routine.
>
>
> I think what you are referring to is generators that are both providers and
> consumers, and not co-routines.

Thanks, Ron, this was very helpful, and makes perfect sense to me.

The framework also handles the other feature that distinguishes
coroutines from consuming generators: returning values.

In a sense, coroutines are not first-class citizens in Python, only
generators are. Coroutines need some supporting framework to be
useful. That's partly what I was trying to address with my `send()`
function. I now see the issue is much deeper than I previously
thought.

Thanks for the discussion, folks!

Best,

Luciano


-- 
Luciano Ramalho
Twitter: @ramalhoorg

Professor em: http://python.pro.br
Twitter: @pythonprobr


More information about the Python-ideas mailing list