[Python-checkins] bpo-38501: Add a warning section to multiprocessing.Pool docs about resource managing (GH-19466)
Miss Islington (bot)
webhook-mailer at python.org
Fri Apr 10 22:11:20 EDT 2020
https://github.com/python/cpython/commit/2e49b5254aa0888dd21a7929be14b6cfe03d56ef
commit: 2e49b5254aa0888dd21a7929be14b6cfe03d56ef
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-04-10T19:11:16-07:00
summary:
bpo-38501: Add a warning section to multiprocessing.Pool docs about resource managing (GH-19466)
(cherry picked from commit 7ec43a73092d43c6c95e7dd2669f49d54b57966f)
Co-authored-by: Pablo Galindo <Pablogsal at gmail.com>
files:
M Doc/library/multiprocessing.rst
diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst
index 6fd509a00caf7..1b850ebced5eb 100644
--- a/Doc/library/multiprocessing.rst
+++ b/Doc/library/multiprocessing.rst
@@ -429,7 +429,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:
@@ -2100,6 +2101,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*
More information about the Python-checkins
mailing list