Optimizing `ThreadPoolExecutor` Sizing for I/O-Bound Tasks

For I/O-bound operations, `ThreadPoolExecutor`'s `max_workers` can exceed the number of CPU cores, as threads spend most time waiting. Python's default `min(32, os.cpu_count() + 4)` is a common starting point, whereas CPU-bound tasks typically require `ProcessPoolExecutor` or fewer threads due to the GIL.

Sources

Open the full topic