Commit 30615854 authored by Serhiy Storchaka's avatar Serhiy Storchaka

issue12085: Use more Pythonic way to check _child_created.

_active shouldn't be cached, it set to None on shutdown.
parent 98a9722e
...@@ -645,6 +645,8 @@ def list2cmdline(seq): ...@@ -645,6 +645,8 @@ def list2cmdline(seq):
class Popen(object): class Popen(object):
_child_created = False # Set here since __del__ checks it
def __init__(self, args, bufsize=0, executable=None, def __init__(self, args, bufsize=0, executable=None,
stdin=None, stdout=None, stderr=None, stdin=None, stdout=None, stderr=None,
preexec_fn=None, close_fds=False, shell=False, preexec_fn=None, close_fds=False, shell=False,
...@@ -653,7 +655,6 @@ class Popen(object): ...@@ -653,7 +655,6 @@ class Popen(object):
"""Create new Popen instance.""" """Create new Popen instance."""
_cleanup() _cleanup()
self._child_created = False
if not isinstance(bufsize, (int, long)): if not isinstance(bufsize, (int, long)):
raise TypeError("bufsize must be an integer") raise TypeError("bufsize must be an integer")
...@@ -750,11 +751,11 @@ class Popen(object): ...@@ -750,11 +751,11 @@ class Popen(object):
return data return data
def __del__(self, _maxint=sys.maxint, _active=_active): def __del__(self, _maxint=sys.maxint):
# If __init__ hasn't had a chance to execute (e.g. if it # If __init__ hasn't had a chance to execute (e.g. if it
# was passed an undeclared keyword argument), we don't # was passed an undeclared keyword argument), we don't
# have a _child_created attribute at all. # have a _child_created attribute at all.
if not getattr(self, '_child_created', False): if not self._child_created:
# We didn't get to successfully create a child process. # We didn't get to successfully create a child process.
return return
# In case the child hasn't been waited on, check if it's done. # In case the child hasn't been waited on, check if it's done.
...@@ -1330,7 +1331,7 @@ class Popen(object): ...@@ -1330,7 +1331,7 @@ class Popen(object):
_WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED, _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
_WEXITSTATUS=os.WEXITSTATUS): _WEXITSTATUS=os.WEXITSTATUS):
# This method is called (indirectly) by __del__, so it cannot # This method is called (indirectly) by __del__, so it cannot
# refer to anything outside of its local scope.""" # refer to anything outside of its local scope.
if _WIFSIGNALED(sts): if _WIFSIGNALED(sts):
self.returncode = -_WTERMSIG(sts) self.returncode = -_WTERMSIG(sts)
elif _WIFEXITED(sts): elif _WIFEXITED(sts):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment