Concurrent futures
Concurrent futures are a new feature added to Python in version 3.2. If you come from a Java-based background, then you may be familiar with ThreadPoolExecutor
. Well, concurrent futures are Python's implementation of this ThreadPoolExecutor
concept.
When it comes to running multithreaded tasks, one of the most computationally expensive tasks is starting up threads. ThreadPoolExecutors
get around this problem by creating a pool of threads that will live as long as we need them to. We no longer have to create and run a thread to perform a task and continue to do this for every task we require; we can, instead, just create a thread once, and then constantly feed it new jobs to do.
A good way to think about this is to imagine you were in an office that had numerous workers. We wouldn't hire an employee, train them up, and then allocate one and only one job to them before firing them. We would, instead, only incur this expensive process of training them up once, and then allocate...