[Python-Dev] Importance of "async" keyword

Nick Coghlan ncoghlan at gmail.com
Sat Jun 27 03:42:32 CEST 2015

On 27 June 2015 at 04:06, Ron Adam <ron3200 at gmail.com> wrote:
> It seems that those points are defined by other means outside of a function
> defined with "async def".  From the PEP...
>    * It is a SyntaxError to have yield or yield from expressions
>      in an async function.
> So somewhere in an async function, it needs to "await something" with a
> yield in it that isn't an async function.

This isn't the case - it can be async functions and C level coroutines
all the way down. Using a generator or other iterable instead requires
adaptation to the awaitable protocol (which makes it possible to tap
into all the work that has been done for the generator-based
coroutines used previously, rather than having to rewrite it to use
native coroutines).

This isn't very clear in the currently released beta as we made some
decisions to simplify the original implementation that we thought
would also be OK from an API design perspective, but turned out to
pose significant problems once folks actually started trying to
integrate native coroutines with other async systems beyond asyncio.

Yury fixed those underlying object model limitations as part of
addressing Ben Darnell's report of problems attempting to integrate
native coroutine support into Tornado

Yury had already updated the PEP to account for those changes, but
I've now also added a specific note regarding the API design change in
response to beta feedback: https://hg.python.org/peps/rev/0c963fa25db8


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list