Skip to content

Commit d06a065

Browse files
committed
Fix potential resource leaks in concurrent.futures.ProcessPoolExecutor
by joining all queues and processes when shutdown() is called.
1 parent db53595 commit d06a065

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/concurrent/futures/process.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def shutdown_worker():
209209
# some multiprocessing.Queue methods may deadlock on Mac OS X.
210210
for p in processes.values():
211211
p.join()
212+
# Release resources held by the queue
213+
call_queue.close()
212214

213215
while True:
214216
_add_call_item_to_queue(pending_work_items,
@@ -246,7 +248,8 @@ def shutdown_worker():
246248
# Clean shutdown of a worker using its PID
247249
# (avoids marking the executor broken)
248250
assert shutting_down()
249-
del processes[result_item]
251+
p = processes.pop(result_item)
252+
p.join()
250253
if not processes:
251254
shutdown_worker()
252255
return

Lib/test/test_concurrent_futures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,8 @@ def test_main():
634634
ThreadPoolAsCompletedTests,
635635
FutureTests,
636636
ProcessPoolShutdownTest,
637-
ThreadPoolShutdownTest)
637+
ThreadPoolShutdownTest,
638+
)
638639
finally:
639640
test.support.reap_children()
640641

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ Core and Builtins
228228
Library
229229
-------
230230

231+
- Fix potential resource leaks in concurrent.futures.ProcessPoolExecutor
232+
by joining all queues and processes when shutdown() is called.
233+
231234
- Issue #11603: Fix a crash when __str__ is rebound as __repr__. Patch by
232235
Andreas Stührk.
233236

0 commit comments

Comments
 (0)