AsyncIO - Implementing AsyncIO¶
To understand how the asyncio
Python standard library works and provides
asynchronous I/O via async/await
syntax. We are going to reimplement it from
scratch.
Rewind: Coroutines¶
coroutine
Coroutines are a more generalized form of subroutines. Subroutines are entered at one point and exited at another point. Coroutines can be entered, exited, and resumed at many different points.
AsyncIO
in Python is based on coroutines. We already know
Generators
/Iterators
are coroutines. Generators
allow suspend the current
function and to return to the caller of the function.
Overview¶
We are going to re-implement the asyncio
Python standard library step-by-step
as it was provided with Python 3.4 initially. This allows for understanding
it’s internals and general concept. Of course we are using simplifications and
skipping some parts like cancellation. These parts are mentioned in the
What’s missing chapter.
- Step 1 - Coroutine Concept
- Step 2 - Multiple Coroutines
- Step 3 - Adding
yield from
- Step 4 - A Loop is running
- Step 5 - A runnable Example
- Step 6 - The Intermediate Function Issue
- Step 7 - The Future
- Step 8 - Extend the Loop
- Step 9 - A Job has to be done
- Step 10 - Scheduling all the time
- Step 11 - Schedule Callbacks
- Step 12 - Back to the Future
- Step 13 - Deduplicate Running Coroutines
- Step 14 - Let’s wait
- Step 15 - And what about real Async IO?
- Step 16 - Cancellation
- What’s missing?
- The Coroutine/Generator Issue