diff options
| author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-31 23:03:00 (GMT) |
|---|---|---|
| committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-31 23:03:00 (GMT) |
| commit | 776e69b5b37a9f0678f2759c145ed26368aaba3f (patch) | |
| tree | 2f26816a6d993a0eb1afe7fc64a87674ab425860 | |
| parent | d9f5292443eb3da4c56a877b7096ad001ee5d848 (diff) | |
| download | cpython-776e69b5b37a9f0678f2759c145ed26368aaba3f.zip cpython-776e69b5b37a9f0678f2759c145ed26368aaba3f.tar.gz cpython-776e69b5b37a9f0678f2759c145ed26368aaba3f.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.py | 5 | ||||
| -rw-r--r-- | Lib/test/test_subprocess.py | 10 | ||||
| -rw-r--r-- | Misc/ACKS | 1 | ||||
| -rw-r--r-- | Misc/NEWS | 4 |
4 files changed, 19 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 3734acd..bdf85fc 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -707,7 +707,10 @@ class Popen(object): def __del__(self, _maxint=sys.maxint, _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 b635ef3..73c1b5c 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -113,6 +113,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"'], @@ -607,6 +607,7 @@ Piet van Oostrum Jason Orendorff Douglas Orr Michele OrrĂ¹ +Oleg Oshmyan Denis S. Otkidach Michael Otteneder R. M. Oudkerk @@ -16,6 +16,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. + Tests ----- |
