diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py index 41e132020e1..7c22a62813f 100644 --- a/Lib/concurrent/futures/process.py +++ b/Lib/concurrent/futures/process.py @@ -209,6 +209,8 @@ def _queue_management_worker(executor_reference, # some multiprocessing.Queue methods may deadlock on Mac OS X. for p in processes.values(): p.join() + # Release resources held by the queue + call_queue.close() while True: _add_call_item_to_queue(pending_work_items, @@ -246,7 +248,8 @@ def _queue_management_worker(executor_reference, # Clean shutdown of a worker using its PID # (avoids marking the executor broken) assert shutting_down() - del processes[result_item] + p = processes.pop(result_item) + p.join() if not processes: shutdown_worker() return diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 222bd5478fc..78a9906d345 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -634,7 +634,8 @@ def test_main(): ThreadPoolAsCompletedTests, FutureTests, ProcessPoolShutdownTest, - ThreadPoolShutdownTest) + ThreadPoolShutdownTest, + ) finally: test.support.reap_children() diff --git a/Misc/NEWS b/Misc/NEWS index e75de01c3db..8d7fb16b5ae 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -228,6 +228,9 @@ Core and Builtins Library ------- +- Fix potential resource leaks in concurrent.futures.ProcessPoolExecutor + by joining all queues and processes when shutdown() is called. + - Issue #11603: Fix a crash when __str__ is rebound as __repr__. Patch by Andreas Stührk.