[Python-checkins] cpython (2.7): issue12085: Use more Pythonic way to check _child_created.

serhiy.storchaka python-checkins at python.org
Mon Feb 10 18:27:53 CET 2014


http://hg.python.org/cpython/rev/734da14489c1
changeset:   89099:734da14489c1
branch:      2.7
parent:      89084:6b10943a5916
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Mon Feb 10 19:19:53 2014 +0200
summary:
  issue12085: Use more Pythonic way to check _child_created.
_active shouldn't be cached, it set to None on shutdown.

files:
  Lib/subprocess.py |  9 +++++----
  1 files changed, 5 insertions(+), 4 deletions(-)


diff --git a/Lib/subprocess.py b/Lib/subprocess.py
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -645,6 +645,8 @@
 
 
 class Popen(object):
+    _child_created = False  # Set here since __del__ checks it
+
     def __init__(self, args, bufsize=0, executable=None,
                  stdin=None, stdout=None, stderr=None,
                  preexec_fn=None, close_fds=False, shell=False,
@@ -653,7 +655,6 @@
         """Create new Popen instance."""
         _cleanup()
 
-        self._child_created = False
         if not isinstance(bufsize, (int, long)):
             raise TypeError("bufsize must be an integer")
 
@@ -750,11 +751,11 @@
         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
         # was passed an undeclared keyword argument), we don't
         # 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.
             return
         # In case the child hasn't been waited on, check if it's done.
@@ -1330,7 +1331,7 @@
                 _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                 _WEXITSTATUS=os.WEXITSTATUS):
             # 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):
                 self.returncode = -_WTERMSIG(sts)
             elif _WIFEXITED(sts):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list