Pycon NL: what’s inside an asyncio event loop? - Taras Kozlov

Tags: python, pycon

(One of my summaries of the 2026 one-day Pycon NL conference in Utrecht, NL).

An asyncio event loop is defined by asyncio.AbstractEventLoop. That’s a large API with more than 50 public methods, but only three are fundamental. At the lowest useful leve, the loop manages callbacks, i/o and timers.

  • We need a way to put events on a queue and a way to grab events from a queue and execute them. call_soon()

  • We need timers too, for callbacks that must be run after some time. call_later()

  • Sleep only knows about time. Often we want to sleep until the next time, unless a socket becomes ready first. So we need a “sleep” that can be interrupted by I/O readiness. add_reader(), add_writer()

His own example implementation of asyncio for educational purposes is at: https://github.com/tarasko/eduloop , it is only 250 lines. Handy if you want to understand asyncio.

He showed this simple example code, incrementally implementing the points above.

The nice thing about asyncio is coroutines. A coroutine is an extended kind of function that can be paused and resumed. The result is a “future”. A future represents an eventual result of an async operation. So: a future is pending until somebody supplies either a result or an exception.

For network connection there’s Transport and Protocol.

https://reinout.vanrees.org/images/2026/pyconnl-8.jpeg

Unrelated photo from our Nelen&Schuurmans company trip to Cologne/Köln in Germany. St. Gereon church.