File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -439,7 +439,8 @@ process which created it.
439
439
>>> def f(x):
440
440
... return x*x
441
441
...
442
- >>> p.map(f, [1,2,3])
442
+ >>> with p:
443
+ ... p.map(f, [1,2,3])
443
444
Process PoolWorker-1:
444
445
Process PoolWorker-2:
445
446
Process PoolWorker-3:
@@ -2127,6 +2128,16 @@ with the :class:`Pool` class.
2127
2128
Note that the methods of the pool object should only be called by
2128
2129
the process which created the pool.
2129
2130
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
+
2130
2141
.. versionadded :: 3.2
2131
2142
*maxtasksperchild *
2132
2143
You can’t perform that action at this time.
0 commit comments