[Python-Dev] async/await in Python; v2

Arnaud Delobelle arnodel at gmail.com
Sat Apr 25 22:47:38 CEST 2015


On Tue, 21 Apr 2015 at 18:27 Yury Selivanov <yselivanov.ml at gmail.com> wrote:
>
> Hi python-dev,
>
> I'm moving the discussion from python-ideas to here.
>
> The updated version of the PEP should be available shortly
> at https://www.python.org/dev/peps/pep-0492
> and is also pasted in this email.
>

Hi Yury,

Having read this very interesting PEP I would like to make two
remarks.  I apologise in advance if they are points which have already
been discussed.

1.  About the 'async for' construct.  Each iteration will create a new
coroutine object (the one returned by Cursor.__anext__()) and it seems
to me that it can be wasteful.  In the example given of an 'aiterable'
Cursor class, probably a large number of rows will fill the cursor
buffer in one call of cursor._prefetch().  However each row that is
iterated over will involve the creation execution of a new coroutine
object.  It seems to me that what is desirable in that case is that
all the buffered rows will be iterated over as in a plain for loop.

2.  I think the semantics of the new coroutine objects could be
defined more clearly in the PEP.  Of course they are pretty obvious
when you know that the coroutines are meant to replace
asyncio.coroutine as described in [1].  I understand that this PEP is
mostly for the benefit of asyncio, hence mainly of interest of people
who know it.  However I think it would be good for it to be more
self-contained.  I have often read a PEP as an introduction to a new
feature of Python.  I feel that if I was not familiar with yield from
and asyncio I would not be able to understand this PEP, even though
potentially one could use the new constructs without knowing anything
about them.

Cheers,

-- 
Arnaud Delobelle

[1] https://docs.python.org/3/library/asyncio-task.html#coroutines


More information about the Python-Dev mailing list