A tiny python asyncio just for learning πββοΈ, document below is my personal notes during the learning, may change frequently.
I implement a series of TCP echo server for the test of tiny-asyncio client including multi threading, IO multiplexing and so on. Details can be found here.
Event loop is just a while True
loop, the basic functionality of event loop is to keep find out which functions can
be executed and execute them. Event loop's implementation I think is not related to coroutine or generator, it's just
a scheduler used to execute functions (even regardless their return value).
The core code in Future
def __await__(self):
yield self
__iter__ = __await__
yield itself. and Task
's __step
will receive bottom future object, and add done callback to them. Notice that
all function will be executed by a global event loop including __step
. I think this part is the core part in asyncio.
What eventually block the program in python design is the yield
, while yield from
(await
) just keep send None
to
generator (or we call coroutine) unless got a StopIteration
, and
x = yield from coro
StopIteration
's value will be assigned to x, notice that if we call return
in generator or coroutine function
it will raise a StopIteration
.
official python selectors module
- get_event_loop
- selectors block
- async sock
- gather
- exception handle, may with bug π€
- creat server
- cancel