[Python-ideas] PEP 525: Asynchronous Generators

Yury Selivanov yselivanov.ml at gmail.com
Fri Aug 5 19:30:49 EDT 2016



On 2016-08-05 4:34 PM, Alexander Shorin wrote:
> Hi Yury!
>
> Thanks for this PEP! This is really what asyncio misses since you made
> async iterators.
>
> As contributor to aiohttp and maintainer of aiocouchdb and few else
> projects I also support this PEP. Great one!
>
> I agree with what Nikolay and Andrew already said: dancing
> around__aiter__/__anext__ to emulate genarator-like behaviour is quite
> boring and complicated. This also makes porting "old synced" code onto
> asyncio harder since you have to rewrite every generator in iterator
> fashion and wrap each with an object that provides __aiter__ /
> __anext__ interface.
>
> For the reference I have is ijson PR[1] that adds asyncio support. If
> we forget about compatibility with 3.3/3.4, with async generators the
> result implementation would be much more elegant and looks more closer
> to the original synced code, because it's all based on generators.
>
> Lack of async generators forces people to implement them on their own
> [2] ones[3], not very effective as the one that could be built-in.
> Also custom interface for each implementation makes hardly to reuse
> them and don't even imagine what happens if two custom async generator
> implementations will met in a single project.
>
> So thank you again, Yury, for pushing this really important and
> missing feature forward!
>
> [1]: https://github.com/isagalaev/ijson/pull/46
> [2]: https://github.com/germn/aiogen
> [3]: https://github.com/ethanfrey/aiojson/blob/master/aiojson/utils/aiogen.py
>

Thank you Alexander for the feedback!  It's really great that asyncio 
users begin to share their experience in this thread.

Indeed, the key idea is to complete async/await implementation, so that 
you can think in async/await terms and use simply use existing Python 
idioms.  Want a context manager in your asyncio application? Use 'async 
with'.  Want an iterator?  Use 'async for' and async generators.

Hopefully we'll get there.

Thank you,
Yury


More information about the Python-ideas mailing list