PyDocs

Nav

Concurrent Execution

ProcessPoolExecutor

concurrent.futures

class (source) not WASI
  • ProcessPoolExecutor(max_workers=None, mp_context=None, initializer=None, initargs=(), max_tasks_per_child=None)
An Executor subclass that executes calls asynchronously using a pool of at most max_workers processes. If max_workers is None or not given, it will default to os.process_cpu_count(). If max_workers is less than or equal to 0, then a ValueError will be raised. On Windows, max_workers must be less than or equal to 61. If it is not then ValueError will be raised. If max_workers is None, then the default chosen will be at most 61, even if more processors are available. mp_context can be a multiprocessing context or None. It will be used to launch the workers. If mp_context is None or not given, the default multiprocessing context is used. See Contexts and start methods.
Changed in 3.3, 3.7, 3.11, 3.12, 3.13, 3.14, 3.15
  • 3.3: When one of the worker processes terminates abruptly, a BrokenProcessPool error is now raised. Previously, behaviour was undefined but operations on the executor or its futures would often freeze or deadlock.
  • 3.7: The mp_context argument was added to allow users to control the start_method for worker processes created by the pool. Added the initializer and initargs arguments.
  • 3.11: The max_tasks_per_child argument was added to allow users to control the lifetime of workers in the pool.
  • 3.12: On POSIX systems, if your application has multiple threads and the multiprocessing context uses the "fork" start method: The os.fork() function called internally to spawn workers may raise a DeprecationWarning. Pass a mp_context configured to use a different start method. See the os.fork() documentation for further explanation.
  • 3.13: max_workers uses os.process_cpu_count() by default, instead of os.cpu_count().
  • 3.14: The default process start method (see Contexts and start methods) changed away from fork. If you require the fork start method for ProcessPoolExecutor you must explicitly pass mp_context=multiprocessing.get_context("fork").
  • 3.15: Fixed a deadlock (gh-115634) where the executor could hang after a worker process exited upon reaching its max_tasks_per_child limit while tasks remained queued.
Members of ProcessPoolExecutor

k

kill_workers
Attempts to kill the executor's workers.

t

terminate_workers
Attempts to terminate the executor's workers.
0 Examples
No examples for concurrent.futures/ProcessPoolExecutor.
See Also
No see-alsos for concurrent.futures/ProcessPoolExecutor
0 Notes
No notes for ProcessPoolExecutor