Asyncio
Python has a native asyncio package that supports async
and await
(similar to JS).
We will be using the lastest Python version 3.11, some features may not be available in older Python versions.
Task Group
In a task group context, tasks are executed concurrently. In the example below, 2 tasks should finish at around the same time.
asyncio.gather()
The gather method also blocks the code from keep running
Queue
Not thread safe.
Queues — Python 3.11.2 documentation
asyncio.Queue
is similar to Golang: WaitGroups
Tasks are created, added to queue and executed concurrently.
task_done()
is called after each job is finished. queue.join()
will wait for all tasks in queue to finish.
How is this guide?