[Python-Dev] PEP 492: async/await in Python; version 5
ryan at ryanhiebert.com
Tue May 5 23:29:44 CEST 2015
This draft proposal for async generators in ECMAScript 7 may be interesting reading to those who haven’t already: https://github.com/jhusain/asyncgenerator <https://github.com/jhusain/asyncgenerator>
This talk also has some good ideas about them, though the interesting stuff about using async generator syntax is all on the last slide, and not really explained: https://www.youtube.com/watch?v=gawmdhCNy-A <https://www.youtube.com/watch?v=gawmdhCNy-A>
> On May 5, 2015, at 3:55 PM, Guido van Rossum <guido at python.org> wrote:
> One small clarification:
> On Tue, May 5, 2015 at 12:40 PM, Jim J. Jewett <jimjjewett at gmail.com <mailto:jimjjewett at gmail.com>> wrote:
> [...] but I don't understand how this limitation works with things like a
> per-line file iterator that might need to wait for the file to
> be initially opened.
> Note that PEP 492 makes it syntactically impossible to use a coroutine function to implement an iterator using yield; this is because the generator machinery is needed to implement the coroutine machinery. However, the PEP allows the creation of asynchronous iterators using classes that implement __aiter__ and __anext__. Any blocking you need to do can happen in either of those. You just use `async for` to iterate over such an "asynchronous stream".
> (There's an issue with actually implementing an asynchronous stream mapped to a disk file, because I/O multiplexing primitives like select() don't actually support waiting for disk files -- but this is an unrelated problem, and asynchronous streams are useful to handle I/O to/from network connections, subprocesses (pipes) or local RPC connections. Checkout the streams <https://docs.python.org/3/library/asyncio-stream.html> and subprocess <https://docs.python.org/3/library/asyncio-subprocess.html> submodules of the asyncio package. These streams would be great candidates for adding __aiter__/__anext__ to support async for-loops, so the idiom for iterating over them can once again closely resemble the idiom for iterating over regular (synchronous) streams using for-loops.)
> --Guido van Rossum (python.org/~guido <http://python.org/~guido>)
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/ryan%40ryanhiebert.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev