
Python: Generators, Coroutines, Native Coroutines and Async/Await - snw
http://masnun.com/2015/11/13/python-generators-coroutines-native-coroutines-and-async-await.html
======
mariocesar
If you don't have the latest asyncio version, change `ensure_future` to
`async`.

> asyncio.async(display_date(1, loop))

See this
[https://github.com/python/asyncio/pull/242](https://github.com/python/asyncio/pull/242)

The author is using the latest release of asyncio, will be good to mention
that.

------
harlowja
Anyone know when most of the python stdlib (the batteries included part) will
start itself using async/await (for any/all things that could block)?? I
suppose it will never change due to backwards compat. (which feels odd...)?

~~~
sametmax
More than that, believe it or not, but synchronicity and blocking code is
considered a feature: it's simple and straighforward.

Most code doesn't need to be non blocking. We only hear so much about non
blocking because the Web is the big thing and Web programming benefits from
it.

But there are hundreds of other fields in programming where IO is not the main
issue, and hence don't need the additional complexity of being async.

Granted, asyncio does a good job at making async easier, but imperative code
will always be easier to use, learn and teach. These qualities are very
important, and made Python famous : easy to grow with, and yet powerful.

So the stdlib will remain as-is, the useful, easy and beautiful thing it has
been.

We may see additions made to it so you can ALSO, when needed, do more stuff
async. But really, I think we will see more and more external lib just doing
that, so for when you DO need async, you will just pip install.

Things I do hope will have an additional async API though:

    
    
        - urllib;
        - sqlite3;
        - subprocess.

~~~
AnkhMorporkian
You know what I've always wanted to see (and it's quite possible one exists; I
have never actively searched for one)? A completely asynchronous programming
language. Every single operation is carried out asynchronously; everything
from addition to while loops.

Synchronization would be a nightmare, but I think it would be a fun exercise
to see what you could do in that framework.

~~~
xyzzy123
Such a language would translate really nicely to hardware. Funnily enough,
verilog / VHDL are the closest I can think of...

You don't get what you would normally think of as "while loops" though, which
makes sense if you think about it.

~~~
krupan
Check out MyHDL and Cocotb:

[http://www.myhdl.org/](http://www.myhdl.org/)

[http://potential.ventures/cocotb/](http://potential.ventures/cocotb/)

------
bawana
Async is not new. life has been doing it for millennia. Your heart does not
stop beating while you breathe, yet both systems are interrelated. The body
accomplishes this through the use of 'buffers'. Pause one system long enough
and the other will fail. So we have evolved a 'scheduler' \- the hindbrain
that starts to scream louder and louder when the event queue of one system
becomes too long. It might be instructive to model this in silicon. Have one
cpu core be the scheduler. Have every set of interrelated processes (that are
Async) register their variables with the scheduler. The scheduler then keeps
track of these sets. When a variable in a set changes, pause that process for
two cycles.

------
macavity23
A good article, but it should mention async network programming (probably with
[http://www.tornadoweb.org/](http://www.tornadoweb.org/)) which is the major
driving use case behind the adoption of async programming patterns.

