Skip to content

Commit 7ec43a7

Browse files
authored
bpo-38501: Add a warning section to multiprocessing.Pool docs about resource managing (GH-19466)
1 parent f13072b commit 7ec43a7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Doc/library/multiprocessing.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ process which created it.
439439
>>> def f(x):
440440
... return x*x
441441
...
442-
>>> p.map(f, [1,2,3])
442+
>>> with p:
443+
... p.map(f, [1,2,3])
443444
Process PoolWorker-1:
444445
Process PoolWorker-2:
445446
Process PoolWorker-3:
@@ -2127,6 +2128,16 @@ with the :class:`Pool` class.
21272128
Note that the methods of the pool object should only be called by
21282129
the process which created the pool.
21292130

2131+
.. warning::
2132+
:class:`multiprocessing.pool` objects have internal resources that need to be
2133+
properly managed (like any other resource) by using the pool as a context manager
2134+
or by calling :meth:`close` and :meth:`terminate` manually. Failure to do this
2135+
can lead to the process hanging on finalization.
2136+
2137+
Note that is **not correct** to rely on the garbage colletor to destroy the pool
2138+
as CPython does not assure that the finalizer of the pool will be called
2139+
(see :meth:`object.__del__` for more information).
2140+
21302141
.. versionadded:: 3.2
21312142
*maxtasksperchild*
21322143

0 commit comments

Comments
 (0)