[Tutor] What exactly does "await" do? (David)(Mats Wichmann)(Alan Gauld)

Alphonsus phonokoye at gmail.com
Fri Feb 17 21:43:33 EST 2023


Good day to you Mr David, Mr Mats and Mr. Alan and also to everyone on
this mailing list, I do appreciate your response to my questions which
have opened up my understanding on the subject, I also apologize for
my delayed response. With this mail message I hope to summarize my
idea of the subject from your messages and other sources on the web.
Please call me out when my statements are wrong. Thank you in advance.

asyncio is python's implementation of Asynchronous IO which in turn is
a form of IO where other tasks may continue before the IO transmission
has ended. This implementation makes use of generators, coroutines,
Task and Future objects.
Coroutines are further divided into simple and native coroutines,
simple coroutines are generators and native coroutines are blocks of
code enclosed in an async def header.

The await keyword is used to suspend the execution of the surrounding
coroutine and begin the execution of the awaited coroutine. (by
coroutine, I speak of the native coroutine) The await function in
itself does not specify that the coroutine will run concurrently with
some other coroutine and coroutines can only run concurrently with
coroutines, but we have to explicitly specify that the coroutines will
run concurrently by using asyncio.gather or creating tasks using
asyncio.create_task and then awaiting the tasks. But all these are
just high level stuff.

The low level stuff involves the asyncio event loop, Future objects
and some concept called a Transport. All  of these may not be used
frequently but are important for greater control over an asyncio
program. These parts of asyncio are probably the most tricky parts. It
is important to understand these parts though, so as to make better
programming decisions. I also do not understand the low level approach
to IO in python. Can I get references that teach these?


More information about the Tutor mailing list