(original) (raw)
changeset: 70049:b00a64a5cb93 branch: 3.2 parent: 70042:0d9837985725 user: Gregory P. Smith greg@krypto.org date: Wed May 11 22🔞23 2011 -0700 files: Doc/library/subprocess.rst Lib/subprocess.py Lib/test/test_subprocess.py Misc/NEWS description: merge - 7a3f3ad83676 Fixes Issue #12044. diff -r 0d9837985725 -r b00a64a5cb93 Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst Wed May 11 14:02:13 2011 -0400 +++ b/Doc/library/subprocess.rst Wed May 11 22🔞23 2011 -0700 @@ -217,8 +217,8 @@ *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: diff -r 0d9837985725 -r b00a64a5cb93 Lib/subprocess.py --- a/Lib/subprocess.py Wed May 11 14:02:13 2011 -0400 +++ b/Lib/subprocess.py Wed May 11 22🔞23 2011 -0700 @@ -764,6 +764,8 @@ 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: diff -r 0d9837985725 -r b00a64a5cb93 Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py Wed May 11 14:02:13 2011 -0400 +++ b/Lib/test/test_subprocess.py Wed May 11 22🔞23 2011 -0700 @@ -1491,7 +1491,8 @@ 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): diff -r 0d9837985725 -r b00a64a5cb93 Misc/NEWS --- a/Misc/NEWS Wed May 11 14:02:13 2011 -0400 +++ b/Misc/NEWS Wed May 11 22🔞23 2011 -0700 @@ -10,6 +10,10 @@ 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. /greg@krypto.org