Tutorial on how to use Asyncio in a Jupyter Notebook
This story will show the basic of using Asyncio in a Jupyter Notebook
Prerequisites
Using Python 3.12. Need to install a few packages via pip along the way, but that will be obvious once we get to that.
The Problem with Notebooks and Asyncio
It is important to understand that when running jobs in asyncio, we are still running in the same thread. Asyncio tasks are functions that run concurrently but under the control of the same event loop. The problem we are facing in a Jupyter Notebook is that the notebook already runs in a thread and already has an event loop running. The causes the problem, that if you assign a asyncio task to the running event loop (that runs jupyter) then the cell will be 'blocked' until the tasks has completed.
References
Python Concurrency With Asyncio
Jupyterlab, Python3, asyncio – asynchronous tasks in a notebook background thread