concurrent.futures as a solution for blocking tasks
In this section, we will be considering another way to implement threading/multiprocessing: the concurrent.futures
module, which is designed to be a high-level interface for implementing asynchronous tasks. Specifically, the concurrent.futures
module works seamlessly with the asyncio
module, and, in addition, it provides an abstract class called Executor
, which contains the skeleton of the two main classes that implement asynchronous threading and multiprocessing, respectively (as suggested by their names): ThreadPoolExecutor
and ProcessPoolExecutor
.
Changes in the framework
Before we jump into the API from concurrent.futures
, let's discuss the theoretical basics of asynchronous threading/multiprocessing, and how it plays into the framework of the asynchronous programming that asyncio
provides.
As a reminder, we have three major elements in our ecosystem of asynchronous programming: the event loop, the coroutines, and their corresponding futures...