(original) (raw)
changeset: 70555:71dfd8cf4bf5 parent: 70553:cb2e3188832b parent: 70554:0f2714e49583 user: Victor Stinner victor.stinner@haypocalc.com date: Wed Jun 01 00:58:57 2011 +0200 files: Lib/subprocess.py Lib/test/test_subprocess.py Misc/ACKS Misc/NEWS description: (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. diff -r cb2e3188832b -r 71dfd8cf4bf5 Lib/subprocess.py --- a/Lib/subprocess.py Tue May 31 17:11:26 2011 -0500 +++ b/Lib/subprocess.py Wed Jun 01 00:58:57 2011 +0200 @@ -775,7 +775,10 @@ 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 -r cb2e3188832b -r 71dfd8cf4bf5 Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py Tue May 31 17:11:26 2011 -0500 +++ b/Lib/test/test_subprocess.py Wed Jun 01 00:58:57 2011 +0200 @@ -146,6 +146,16 @@ 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 -r cb2e3188832b -r 71dfd8cf4bf5 Misc/ACKS --- a/Misc/ACKS Tue May 31 17:11:26 2011 -0500 +++ b/Misc/ACKS Wed Jun 01 00:58:57 2011 +0200 @@ -688,6 +688,7 @@ Jason Orendorff Douglas Orr Michele OrrĂ¹ +Oleg Oshmyan Denis S. Otkidach Michael Otteneder R. M. Oudkerk diff -r cb2e3188832b -r 71dfd8cf4bf5 Misc/NEWS --- a/Misc/NEWS Tue May 31 17:11:26 2011 -0500 +++ b/Misc/NEWS Wed Jun 01 00:58:57 2011 +0200 @@ -184,6 +184,10 @@ 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(). /victor.stinner@haypocalc.com