]> granicus.if.org Git - python/commitdiff
Fix potential resource leaks in concurrent.futures.ProcessPoolExecutor
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 15 Jul 2011 23:13:34 +0000 (01:13 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 15 Jul 2011 23:13:34 +0000 (01:13 +0200)
by joining all queues and processes when shutdown() is called.

Lib/concurrent/futures/process.py
Lib/test/test_concurrent_futures.py
Misc/NEWS

index 41e132020e1799d457924569a3fcbdfb1a063093..7c22a62813fc2fcc3309aa0a239b1604d1714abd 100644 (file)
@@ -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
index 222bd5478fc1a14bd90b98fa9d8df5fe96c00cba..78a9906d3459c0750d0ae905fb5974206f4ac6f1 100644 (file)
@@ -634,7 +634,8 @@ def test_main():
                                   ThreadPoolAsCompletedTests,
                                   FutureTests,
                                   ProcessPoolShutdownTest,
-                                  ThreadPoolShutdownTest)
+                                  ThreadPoolShutdownTest,
+                                  )
     finally:
         test.support.reap_children()
 
index e75de01c3db0b33cf4b0ff8a0ef76ccb74aae4bf..8d7fb16b5aebe2b1345c7ff3af3084a52ec4006c 100644 (file)
--- 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.