summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-31 22:57:47 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-31 22:57:47 (GMT)
commit87b9bc3893bac402bd773a83ee6734507f978607 (patch)
tree11a077f4d4f36f6bbb7b5d2661c4d326e24cc8df
parentee49797c8dacb886d58804e59f6431ea6f842be2 (diff)
downloadcpython-87b9bc3893bac402bd773a83ee6734507f978607.zip
cpython-87b9bc3893bac402bd773a83ee6734507f978607.tar.gz
cpython-87b9bc3893bac402bd773a83ee6734507f978607.tar.bz2
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 28dd691..4bcf159 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -768,7 +768,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 ad89864..9d66659 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -121,6 +121,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 d0e32e1..aa077fc 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -650,6 +650,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 4ab11a5..3703ac5 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,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 #985064: Make plistlib more resilient to faulty input plists.
Patch by Mher Movsisyan.