GitHub

@@ -707,6 +707,9 @@ def getoutput(cmd):

707707708708709709

class Popen(object):

710+711+

_child_created = False # Set here since __del__ checks it

712+710713

def __init__(self, args, bufsize=-1, executable=None,

711714

stdin=None, stdout=None, stderr=None,

712715

preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,

@@ -717,7 +720,6 @@ def __init__(self, args, bufsize=-1, executable=None,

717720

"""Create new Popen instance."""

718721

_cleanup()

719722720-

self._child_created = False

721723

self._input = None

722724

self._communication_started = False

723725

if bufsize is None:

@@ -859,11 +861,8 @@ def __exit__(self, type, value, traceback):

859861

# Wait for the process to terminate, to avoid zombies.

860862

self.wait()

861863862-

def __del__(self, _maxsize=sys.maxsize, _active=_active):

863-

# If __init__ hasn't had a chance to execute (e.g. if it

864-

# was passed an undeclared keyword argument), we don't

865-

# have a _child_created attribute at all.

866-

if not getattr(self, '_child_created', False):

864+

def __del__(self, _maxsize=sys.maxsize):

865+

if not self._child_created:

867866

# We didn't get to successfully create a child process.

868867

return

869868

# In case the child hasn't been waited on, check if it's done.

@@ -1446,7 +1445,7 @@ def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,

14461445

_WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,

14471446

_WEXITSTATUS=os.WEXITSTATUS):

14481447

# This method is called (indirectly) by __del__, so it cannot

1449-

# refer to anything outside of its local scope."""

1448+

# refer to anything outside of its local scope.

14501449

if _WIFSIGNALED(sts):

14511450

self.returncode = -_WTERMSIG(sts)

14521451

elif _WIFEXITED(sts):

Read the original on github.com ↗