PyDocs

Nav

Concurrent Execution

ThreadPoolExecutor

concurrent.futures

class (source) not WASI
  • ThreadPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=(), **ctxkwargs)
An Executor subclass that uses a pool of at most max_workers threads to execute calls asynchronously.
Changed in 3.5, 3.6, 3.7, 3.8, 3.13, 3.14
  • 3.5: If max_workers is None or not given, it will default to the number of processors on the machine, multiplied by 5, assuming that ThreadPoolExecutor is often used to overlap I/O instead of CPU work and the number of workers should be higher than the number of workers for ProcessPoolExecutor.
  • 3.6: Added the thread_name_prefix parameter to allow users to control the threading.Thread names for worker threads created by the pool for easier debugging.
  • 3.7: Added the initializer and initargs arguments.
  • 3.8: Default value of max_workers is changed to min(32, os.cpu_count() + 4). This default value preserves at least 5 workers for I/O bound tasks. It utilizes at most 32 CPU cores for CPU bound tasks which release the GIL. And it avoids using very large resources implicitly on many-core machines. ThreadPoolExecutor now reuses idle worker threads before starting max_workers worker threads too.
  • 3.13: Default value of max_workers is changed to min(32, (os.process_cpu_count() or 1) + 4).
  • 3.14: Added ctxkwargs to pass additional arguments to prepare_context() class method.
Members of ThreadPoolExecutor

p

prepare_context
Setting up the necessary context for creating worker instances in a pool-based executor (for example, in a concurrent environment like threads or interpreters).
0 Examples
No examples for concurrent.futures/ThreadPoolExecutor.
See Also
No see-alsos for concurrent.futures/ThreadPoolExecutor
0 Notes
No notes for ThreadPoolExecutor