Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 53c89fb

Browse files
committed
bpo-19675: Terminate processes if construction of a pool is failing.
1 parent 8ff5356 commit 53c89fb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Lib/multiprocessing/pool.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,15 @@ def __init__(self, processes=None, initializer=None, initargs=(),
173173

174174
self._processes = processes
175175
self._pool = []
176-
self._repopulate_pool()
176+
try:
177+
self._repopulate_pool()
178+
except Exception:
179+
for p in self._pool:
180+
if p.exitcode is None:
181+
p.terminate()
182+
for p in self._pool:
183+
p.join()
184+
raise
177185

178186
self._worker_handler = threading.Thread(
179187
target=Pool._handle_workers,
@@ -235,10 +243,10 @@ def _repopulate_pool(self):
235243
self._initargs, self._maxtasksperchild,
236244
self._wrap_exception)
237245
)
238-
self._pool.append(w)
239246
w.name = w.name.replace('Process', 'PoolWorker')
240247
w.daemon = True
241248
w.start()
249+
self._pool.append(w)
242250
util.debug('added worker')
243251

244252
def _maintain_pool(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
multiprocessing.Pool does no longer leak processes if the construction of
2+
the pool fails.

0 commit comments

Comments
 (0)