PyDocs

Nav

Concurrent Execution

Pool

  • Pool([processes[, initializer[, initargs[, maxtasksperchild[, context]]]]])
Class which supports an async version of applying functions to arguments.
Changed in 3.2, 3.3, 3.4, 3.13
  • 3.2: Added the maxtasksperchild parameter.
  • 3.3: Pool objects now support the context management protocol – see Context Manager Types. __enter__() returns the pool object, and __exit__() calls terminate().
  • 3.4: Added the context parameter.
  • 3.13: processes uses os.process_cpu_count() by default, instead of os.cpu_count().
Members of Pool

a

apply
Equivalent of `func(*args, **kwds)`.
apply_async
Asynchronous version of `apply()` method.

c

close
Prevents any more tasks from being submitted to the pool.

i

imap
Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
imap_unordered
Like `imap()` method but ordering of results is arbitrary.

j

join
Wait for the worker processes to exit.

m

map
Apply `func` to each element in `iterable`, collecting the results in a list that is returned.
map_async
Asynchronous version of `map()` method.

s

starmap
Like `map()` method but the elements of the `iterable` are expected to be iterables as well and will be unpacked as arguments.
starmap_async
Asynchronous version of `starmap()` method.

t

terminate
Stops the worker processes immediately without completing outstanding work.
1 Example
>>> from multiprocessing import Pool
>>> p = Pool(5)
>>> def f(x):
...     return x*x
...
>>> with p:
...     p.map(f, [1,2,3])
Process PoolWorker-1:
Process PoolWorker-2:
Process PoolWorker-3:
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
AttributeError: Can't get attribute 'f' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>
AttributeError: Can't get attribute 'f' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>
AttributeError: Can't get attribute 'f' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>
from the Python docs
See Also
No see-alsos for multiprocessing.pool/Pool
0 Notes
No notes for Pool