[Python-checkins] cpython: Fix potential resource leaks in concurrent.futures.ProcessPoolExecutor

antoine.pitrou python-checkins at python.org
Sat Jul 16 01:18:20 CEST 2011


http://hg.python.org/cpython/rev/0fe200e4f8b4
changeset:   71373:0fe200e4f8b4
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Sat Jul 16 01:13:34 2011 +0200
summary:
  Fix potential resource leaks in concurrent.futures.ProcessPoolExecutor
by joining all queues and processes when shutdown() is called.

files:
  Lib/concurrent/futures/process.py   |  5 ++++-
  Lib/test/test_concurrent_futures.py |  3 ++-
  Misc/NEWS                           |  3 +++
  3 files changed, 9 insertions(+), 2 deletions(-)


diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py
--- a/Lib/concurrent/futures/process.py
+++ b/Lib/concurrent/futures/process.py
@@ -209,6 +209,8 @@
         # 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 @@
             # 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
--- a/Lib/test/test_concurrent_futures.py
+++ b/Lib/test/test_concurrent_futures.py
@@ -634,7 +634,8 @@
                                   ThreadPoolAsCompletedTests,
                                   FutureTests,
                                   ProcessPoolShutdownTest,
-                                  ThreadPoolShutdownTest)
+                                  ThreadPoolShutdownTest,
+                                  )
     finally:
         test.support.reap_children()
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -228,6 +228,9 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list