(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.
This commit is contained in:
Victor Stinner 2011-06-01 00:58:57 +02:00
commit 1b5b9d7434
4 changed files with 19 additions and 1 deletions

View file

@ -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.