[Python-Dev] PEP 492: What is the real goal?

Guido van Rossum guido at python.org
Thu Apr 30 21:32:02 CEST 2015


On Thu, Apr 30, 2015 at 11:41 AM, Jim J. Jewett <jimjjewett at gmail.com>
wrote:

>
> On Wed Apr 29 20:06:23 CEST 2015,Yury Selivanov replied:
>
> >> As best I can guess, the difference seems to be that a "normal"
> >> generator is using yield primarily to say:
>
> >>      "I'm not done; I have more values when you want them",
>

This seems so vague as to be useless to me. When using generators to
implement iterators, "yield" very specifically means "here is the next
value in the sequence I'm generating". (And to indicate there are no more
values you have to use "return".)


> >> but an asynchronous (PEP492) coroutine is primarily saying:
>
> >>      "This might take a while, go ahead and do something else
> meanwhile."
>
> > Correct.
>

Actually that's not even wrong. When using generators as coroutines, PEP
342 style, "yield" means "I am blocked waiting for a result that the I/O
multiplexer is eventually going to produce". The argument to yield tells
the multiplexer what the coroutine is waiting for, and it puts the
generator stack frame on an appropriate queue. When the multiplexer has
obtained the requested result it resumes the coroutine by using send() with
that value, which resumes the coroutine/generator frame, making that value
the return value from yield.

Read Greg Ewing's tutorial for more color:
http://www.cosc.canterbury.ac.nz/greg.ewing/python/yield-from/yield_from.html

Then I strongly request a more specific name than coroutine.
>

No, this is the name we've been using since PEP 342 and it's still the same
concept.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150430/33ac1b96/attachment-0001.html>


More information about the Python-Dev mailing list