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

Lines changed: 10 additions & 2 deletions
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):
Lines changed: 2 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy