summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-31 22:58:57 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-31 22:58:57 (GMT)
commit1b5b9d7434ad3c082ec96688e8d0e7edf6b8c432 (patch)
treefbf7948bdc6d76c38441b23fc6ff3e7faf32df43
parent0bb299165344129dcdc0891233f3799ca258d4a3 (diff)
parent87b9bc3893bac402bd773a83ee6734507f978607 (diff)
downloadcpython-1b5b9d7434ad3c082ec96688e8d0e7edf6b8c432.zip
cpython-1b5b9d7434ad3c082ec96688e8d0e7edf6b8c432.tar.gz
cpython-1b5b9d7434ad3c082ec96688e8d0e7edf6b8c432.tar.bz2
(Merge 3.2) Close #12085: Fix an attribute error in subprocess.Popen destructor
if the constructor has failed, e.g. because of an undeclared keyword argument. Patch written by Oleg Oshmyan.
-rw-r--r--Lib/subprocess.py5
-rw-r--r--Lib/test/test_subprocess.py10
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS4
4 files changed, 19 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 6e0cf06..49137d4 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -775,7 +775,10 @@ class Popen(object):
self.wait()
def __del__(self, _maxsize=sys.maxsize, _active=_active):
- if not self._child_created:
+ # If __init__ hasn't had a chance to execute (e.g. if it
+ # was passed an undeclared keyword argument), we don't
+ # have a _child_created attribute at all.
+ if not getattr(self, '_child_created', False):
# We didn't get to successfully create a child process.
return
# In case the child hasn't been waited on, check if it's done.
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 686c1b1..859df34 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -146,6 +146,16 @@ class ProcessTestCase(BaseTestCase):
env=newenv)
self.assertEqual(rc, 1)
+ def test_invalid_args(self):
+ # Popen() called with invalid arguments should raise TypeError
+ # but Popen.__del__ should not complain (issue #12085)
+ with support.captured_stderr() as s:
+ self.assertRaises(TypeError, subprocess.Popen, invalid_arg_name=1)
+ argcount = subprocess.Popen.__init__.__code__.co_argcount
+ too_many_args = [0] * (argcount + 1)
+ self.assertRaises(TypeError, subprocess.Popen, *too_many_args)
+ self.assertEqual(s.getvalue(), '')
+
def test_stdin_none(self):
# .stdin is None when not redirected
p = subprocess.Popen([sys.executable, "-c", 'print("banana")'],
diff --git a/Misc/ACKS b/Misc/ACKS
index 93ec35f..e4aa789 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -688,6 +688,7 @@ Piet van Oostrum
Jason Orendorff
Douglas Orr
Michele OrrĂ¹
+Oleg Oshmyan
Denis S. Otkidach
Michael Otteneder
R. M. Oudkerk
diff --git a/Misc/NEWS b/Misc/NEWS
index 7c82dbe..b85de50 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -184,6 +184,10 @@ Core and Builtins
Library
-------
+- Issue #12085: Fix an attribute error in subprocess.Popen destructor if the
+ constructor has failed, e.g. because of an undeclared keyword argument. Patch
+ written by Oleg Oshmyan.
+
- Issue #12028: Make threading._get_ident() public, rename it to
threading.get_ident() and document it. This function was already used using
_thread.get_ident().