[Python-Dev] PEP 492: async/await in Python; version 5
Guido van Rossum
guido at python.org
Thu May 7 19:42:52 CEST 2015
On Tue, May 5, 2015 at 3:36 PM, Rajiv Kumar <rajiv.kumar at gmail.com> wrote:
> I wrote a little example that has a bare-bones implementation of Go
> style channels via a custom event loop. I used it to translate the prime
> sieve example from Go almost directly to Python. The code uses "message
> = await channel.receive()" to mimic Go's "message <- channel". Instead of
> using "go func()" to fire off a goroutine, I add the PEP492 coroutine to my
> simple event loop.
It's not an efficient implementation - really just a proof of concept that
> you can use async/await in your own code without any reference to asyncio.
> I ended up writing it as I was thinking about how PEP 342 style coroutines
> might look like in an async/await world.
> In the course of writing this, I did find that it would be useful to have
> the PEP document how event loops should advance the coroutines (via
> .send(None) for example). It would also be helpful to have the semantics of
> how await interacts with different kinds of awaitables documented. I had to
> play with Yury's implementation to see what it does if the __await__ just
> returns iter([1,2,3]) for example.
I've found this too. :-) Yury, perhaps you could show a brief example in
the PEP of how to "drive" a coroutine from e.g. main()?
> - Rajiv
>  https://gist.github.com/vrajivk/c505310fb79d412afcd5#file-sieve-py
>  https://golang.org/doc/play/sieve.go
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev