Compared to concurrent.futures.ThreadPoolExecutor:
Better performance and efficiency:
- Much less overhead per task. This means you can usefully parallelize more cases where there are many tasks and/or fast tasks.
- Limit how many tasks are iterated over, even when
buffersizeis not used, reducing memory usage when lazy task creation is used.
Correctness:
contextvarscontext is propagated from the time a task is scheduled, rather than the thread pool creation. See this discussion for details.
More flexibility in API design:
map(func, *iterables, return_in_order=False)allows for results to be returned when finished, rather than in order. This can speed up execution slightly.