PyConDE & PyData Berlin 2024

AsyncApp. My contribution to hype Pythons asyncio a bit more
04-24, 10:30–11:00 (Europe/Berlin), B07-B08

Asyncio use is now everywhere in the Python world, ...

.. or is it?

Being there since version 3.4 my impression is, that it is still not the go to solution when starting off new projects.
It's not an obvious choice and traditional approaches still seem to be much preferred especially by beginners.

So let me take you with me on a journey to create simple, yet powerful building blocks to build asyncio based applications using patterns that are easy to follow, lightweight and attractive.

asyncio #click #logging #psutil #redis #raspberrypi


Asyncio has been introduced as a possible solution mainly for I/O related performance problems.

The traditional way to handle I/O often ends up in code, which blocks the execution of concurrent elements in an application, often resulting in bad performance.

The usual suspects when dealing with these problems, such as multiprocessing and threading, are often considered to be complex and not straightforward in use, especially for beginners.
I believe that proper threading and multiprocessing, with all its interprocess or shared memory communication, locks and race condition prevention, as well as efficient object handling still requires a deep understanding of the architecture and inner workings, and is still mainly a topic for experts.

Asyncio comes to the rescue here offering a layer of abstraction at a lower and much easier to understand layer.
While it is no solution to aid in distributing code execution to gain more performance, it will solve the blocking issues quite effiently.

To demonstrate the power and simplicity of asyncio I will show a few object orientated building blocks that will allow us to create a simple environment monitoring app for the raspberry pi.

This app will

  • periodically gather sensor readings
  • log them
  • store the readings to a data file
  • offer a monitoring system to log cpu and memory usage for itself
  • be able to be configured via environment variables, config files and command line arguments

In its final iteration the app will be distributed into small parts just dealing with a single, very specific task to be performed, following the traditional UNIX philosophy for an app to do just one thing, but do this well.


Abstract as a tweet (X) or toot (Mastodon)

Asyncio based code is still not the go-to solution for many when starting new Python projects. Let me show you a simple and attractive asyncio based approach for console applications to address that.

Expected audience expertise: Domain

Novice

Expected audience expertise: Python

Novice

A physicist who has filled a variety of roles in a leading service company in the oil and gas industry, currently tackling the development of embedded devices at Rosenxt based on the Raspberry Pi, LinuX and Python with a Python history going back to version 1.4.

This speaker also appears in: