Summary
In this chapter, we saw how to use asynchronous I/O in Python using asyncio
. For many scenarios, the asyncio
module is still a bit raw and unfinished, but there should not be any obstacles in using it. Creating a fully functional server/client setup is still a tad complicated, but the most obvious use of asyncio
is the handling of basic network I/O such as database connections and external resources such as websites. Especially, the latter takes only a few lines to implement with the use of asyncio
, removing some very important bottlenecks from your code.
The point of this chapter is understanding how to tell Python to wait for results in the background instead of simply waiting or polling for them as usual. In Chapter 13, Multiprocessing – When a Single CPU Core Is Not Enough you will learn about multiprocessing, which is also an option for handling stalling resources. However, the goal of multiprocessing is actually to use multiple processors instead of handling stalling resources...