mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
issue12085: Use more Pythonic way to check _child_created.
_active shouldn't be cached, it set to None on shutdown.
This commit is contained in:
commit
580e007860
1 changed files with 6 additions and 7 deletions
|
|
@ -738,6 +738,9 @@ _PLATFORM_DEFAULT_CLOSE_FDS = object()
|
||||||
|
|
||||||
|
|
||||||
class Popen(object):
|
class Popen(object):
|
||||||
|
|
||||||
|
_child_created = False # Set here since __del__ checks it
|
||||||
|
|
||||||
def __init__(self, args, bufsize=-1, executable=None,
|
def __init__(self, args, bufsize=-1, executable=None,
|
||||||
stdin=None, stdout=None, stderr=None,
|
stdin=None, stdout=None, stderr=None,
|
||||||
preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,
|
preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,
|
||||||
|
|
@ -748,7 +751,6 @@ class Popen(object):
|
||||||
"""Create new Popen instance."""
|
"""Create new Popen instance."""
|
||||||
_cleanup()
|
_cleanup()
|
||||||
|
|
||||||
self._child_created = False
|
|
||||||
self._input = None
|
self._input = None
|
||||||
self._communication_started = False
|
self._communication_started = False
|
||||||
if bufsize is None:
|
if bufsize is None:
|
||||||
|
|
@ -890,11 +892,8 @@ class Popen(object):
|
||||||
# Wait for the process to terminate, to avoid zombies.
|
# Wait for the process to terminate, to avoid zombies.
|
||||||
self.wait()
|
self.wait()
|
||||||
|
|
||||||
def __del__(self, _maxsize=sys.maxsize, _active=_active):
|
def __del__(self, _maxsize=sys.maxsize):
|
||||||
# If __init__ hasn't had a chance to execute (e.g. if it
|
if not self._child_created:
|
||||||
# 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.
|
# 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.
|
||||||
|
|
@ -1446,7 +1445,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):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue