diff -r 0fd72636de2b Lib/subprocess.py --- a/Lib/subprocess.py Fri Sep 20 23:28:27 2013 +0300 +++ b/Lib/subprocess.py Mon Sep 23 15:47:29 2013 +0300 @@ -731,6 +731,9 @@ class Popen(object): + + _child_created = False # Set here since __del__ checks it + def __init__(self, args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS, @@ -741,7 +744,6 @@ """Create new Popen instance.""" _cleanup() - self._child_created = False self._input = None self._communication_started = False if bufsize is None: @@ -883,11 +885,8 @@ # Wait for the process to terminate, to avoid zombies. self.wait() - def __del__(self, _maxsize=sys.maxsize, _active=_active): - # 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): + def __del__(self, _maxsize=sys.maxsize): + if not self._child_created: # 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. @@ -1430,7 +1429,7 @@ def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED, _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED, - _WEXITSTATUS=os.WEXITSTATUS): + _WEXITSTATUS=os.WEXITSTATUS, _SubprocessError=SubprocessError): # This method is called (indirectly) by __del__, so it cannot # refer to anything outside of its local scope.""" if _WIFSIGNALED(sts): @@ -1439,11 +1438,11 @@ self.returncode = _WEXITSTATUS(sts) else: # Should never happen - raise SubprocessError("Unknown child exit status!") + raise _SubprocessError("Unknown child exit status!") def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid, - _WNOHANG=os.WNOHANG, _ECHILD=errno.ECHILD): + _WNOHANG=os.WNOHANG, _ECHILD=errno.ECHILD, _OSError=OSError): """Check if child process has terminated. Returns returncode attribute. @@ -1456,7 +1455,7 @@ pid, sts = _waitpid(self.pid, _WNOHANG) if pid == self.pid: self._handle_exitstatus(sts) - except OSError as e: + except _OSError as e: if _deadstate is not None: self.returncode = _deadstate elif e.errno == _ECHILD: