Asynchronous examples
One of the most common reasons for stalling scripts and applications is the usage of remote resources, where remote means any interaction with the network, filesystem, or other resources. With asyncio
, at least a large portion of that is easily fixable. Fetching multiple remote resources and serving to multiple clients is quite a bit easier and more lightweight than it used to be. While both multithreading and multiprocessing can be used for these cases as well, asyncio
is a much lighter alternative that is actually easier to manage in many cases.
The next few sections show a few examples of how to implement certain operations using asyncio
.
Before you start implementing your own code and copying the examples here, I would recommend doing a quick search on the web for whichever library you are looking for and seeing if there is an asyncio
version available.
In general, looking for “asyncio <protocol>” will give you great results...