]> granicus.if.org Git - python/commitdiff
merge - 7a3f3ad83676 Fixes Issue #12044.
authorGregory P. Smith <greg@krypto.org>
Thu, 12 May 2011 05:18:23 +0000 (22:18 -0700)
committerGregory P. Smith <greg@krypto.org>
Thu, 12 May 2011 05:18:23 +0000 (22:18 -0700)
Doc/library/subprocess.rst
Lib/subprocess.py
Lib/test/test_subprocess.py
Misc/NEWS

index e09994ce7d56cec530391f6bbfbf4c9998930a39..4c0edb3ebb46f383c306bb1436ef4bea79f221c7 100644 (file)
@@ -217,8 +217,8 @@ This module defines one class called :class:`Popen`:
    *creationflags*, if given, can be :data:`CREATE_NEW_CONSOLE` or
    :data:`CREATE_NEW_PROCESS_GROUP`. (Windows only)
 
-   Popen objects are supported as context managers via the :keyword:`with` statement,
-   closing any open file descriptors on exit.
+   Popen objects are supported as context managers via the :keyword:`with` statement:
+   on exit, standard file descriptors are closed, and the process is waited for.
    ::
 
       with Popen(["ifconfig"], stdout=PIPE) as proc:
index 9856e6a3330684d290f7de2d40742e0fc1b50359..a5381da44075fcc0163aa57e9da5f49e0022a795 100644 (file)
@@ -764,6 +764,8 @@ class Popen(object):
             self.stderr.close()
         if self.stdin:
             self.stdin.close()
+        # Wait for the process to terminate, to avoid zombies.
+        self.wait()
 
     def __del__(self, _maxsize=sys.maxsize, _active=_active):
         if not self._child_created:
index 4ec754c8aae41f6e07a03ae74a1ad53aed7b6f90..176ff108e6fe166719b9895554b8dd5f8b6190f1 100644 (file)
@@ -1491,7 +1491,8 @@ class ContextManagerTests(ProcessTestCase):
     def test_returncode(self):
         with subprocess.Popen([sys.executable, "-c",
                                "import sys; sys.exit(100)"]) as proc:
-            proc.wait()
+            pass
+        # __exit__ calls wait(), so the returncode should be set
         self.assertEqual(proc.returncode, 100)
 
     def test_communicate_stdin(self):
index b8b65d249dbf32c9d118dc38cd39aa2b68c7bf8e..de0ce38511ebb9358c9909452859a2ae3cc7761b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.2.1?
 Core and Builtins
 -----------------
 
+- Issue #12044: Fixed subprocess.Popen when used as a context manager to
+  wait for the process to end when exiting the context to avoid unintentionally
+  leaving zombie processes around.
+
 - Issue #1195: Fix input() if it is interrupted by CTRL+d and then CTRL+c,
   clear the end-of-file indicator after CTRL+d.