Asyncio -- delayed calculation

Chris Angelico rosuav at gmail.com
Wed Nov 30 07:53:28 EST 2016


On Wed, Nov 30, 2016 at 11:40 PM, Gregory Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Chris Angelico wrote:
>>
>> From the point of view of
>> the rest of Python, no. It's a sign saying "Okay, Python, you can
>> alt-tab away from me now".
>
>
> The problem with that statement is it implies that if
> you omit the "await", then the thing you're calling
> will run uninterruptibly. Whereas what actually happens
> is that it doesn't get run at all.

That's because you're not actually running anything concurrently.
Until you wait for something to be done, it doesn't start happening.
Asynchronous I/O gives the illusion of concurrency, but actually,
everything's serialized.

I think a lot of the confusion around asyncio comes from people not
understanding the fundamentals of what's going on; there are
complexities to the underlying concepts that can't be hidden by any
framework. No matter what you do, you can't get away from them.
They're not asyncio's fault. They're not async/await's fault. They're
not the fault of having forty-two thousand different ways to do
things. They're fundamentals.

I also think that everyone should spend some time writing
multithreaded code before switching to asyncio. It'll give you a
better appreciation for what's going on.

ChrisA



More information about the Python-list mailing list