The concurrent.futures module provides a common high level interface for asynchronously executing callables using pools of threads or processes.
concurrent.futures.Executor is a class to execute function calls asynchronously. The important methods are
submit(function, args), which calls the specified function passing in the given arguments, and
map(function, iterables) which calls the specified function asynchronously passing in each iterable as an argument for a separate function call. This should not be used directly, but is used through its subclasses
Let’s jump into an example. The purpose of the following program is to find the sum of all prime numbers until the given number. There are two functions to demonstrate how to use a pool of threads and how to use a pool of processes.
sum_primes_thread(nums) uses threads and
sum_primes_process(nums) uses processes. Notice that the only difference between the two functions is that one uses
ThreadPoolExecutor while the other uses