[Python-Dev] Using async/await in place of yield expression

Paul Sokolovsky pmiscml at gmail.com
Mon Nov 27 04:57:11 EST 2017


Hello,

On Mon, 27 Nov 2017 15:33:51 +1000
Caleb Hattingh <caleb.hattingh at gmail.com> wrote:

[]

> The PEP only says that __await__ must return an iterator, but it
> turns out that it's also required that that iterator
> should not return any intermediate values.  This requirement is only
> enforced in the event loop, not
> in the `await` call itself.  I was surprised by that:

[]

> So we drive the coroutine manually using send(), and we see that
> intermediate calls return the illegally-yielded values.  I broke the

You apparently mix up the language and a particular asynchronous
scheduling library (even if that library ships with the language).

There're gazillion of async scheduling libraries for Python, and at
least some of them welcome use of "yield" in coroutines (even if
old-style). Moreover, you can always use yield in your own generators,
over which you iterate yourself, all running in the coroutine async
scheduler. When you do this, you will need to check type of values you
get from iteration - if those are "yours", you consume them, if they're
not yours, you re-yield them for higher levels to consume (ultimately,
for the scheduler itself).


-- 
Best regards,
 Paul                          mailto:pmiscml at gmail.com


More information about the Python-Dev mailing list