Skip to content

Commit

Permalink
bpo-38501: Add a warning section to multiprocessing.Pool docs about r…
Browse files Browse the repository at this point in the history
…esource managing (GH-19466)
  • Loading branch information
pablogsal committed Apr 11, 2020
1 parent f13072b commit 7ec43a7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Doc/library/multiprocessing.rst
Expand Up @@ -439,7 +439,8 @@ process which created it.
>>> def f(x):
... return x*x
...
>>> p.map(f, [1,2,3])
>>> with p:
... p.map(f, [1,2,3])
Process PoolWorker-1:
Process PoolWorker-2:
Process PoolWorker-3:
Expand Down Expand Up @@ -2127,6 +2128,16 @@ with the :class:`Pool` class.
Note that the methods of the pool object should only be called by
the process which created the pool.

.. warning::
:class:`multiprocessing.pool` objects have internal resources that need to be
properly managed (like any other resource) by using the pool as a context manager
or by calling :meth:`close` and :meth:`terminate` manually. Failure to do this
can lead to the process hanging on finalization.

Note that is **not correct** to rely on the garbage colletor to destroy the pool
as CPython does not assure that the finalizer of the pool will be called
(see :meth:`object.__del__` for more information).

.. versionadded:: 3.2
*maxtasksperchild*

Expand Down

0 comments on commit 7ec43a7

Please sign in to comment.