[Python-checkins] cpython: Reindent properly.

gregory.p.smith python-checkins at python.org
Thu Jun 2 20:16:09 EDT 2016


https://hg.python.org/cpython/rev/470058bcec44
changeset:   101631:470058bcec44
user:        Gregory P. Smith <greg at krypto.org> [Google Inc.]
date:        Fri Jun 03 00:16:02 2016 +0000
summary:
  Reindent properly.

files:
  Lib/socketserver.py |  138 +++++++++++++++----------------
  1 files changed, 68 insertions(+), 70 deletions(-)


diff --git a/Lib/socketserver.py b/Lib/socketserver.py
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -540,87 +540,85 @@
         pass
 
 if hasattr(os, "fork"):
-  # Non-standard indentation on this statement to avoid reindenting the body.
-  class ForkingMixIn:
+    class ForkingMixIn:
+        """Mix-in class to handle each request in a new process."""
 
-    """Mix-in class to handle each request in a new process."""
+        timeout = 300
+        active_children = None
+        max_children = 40
 
-    timeout = 300
-    active_children = None
-    max_children = 40
+        def collect_children(self):
+            """Internal routine to wait for children that have exited."""
+            if self.active_children is None:
+                return
 
-    def collect_children(self):
-        """Internal routine to wait for children that have exited."""
-        if self.active_children is None:
-            return
+            # If we're above the max number of children, wait and reap them until
+            # we go back below threshold. Note that we use waitpid(-1) below to be
+            # able to collect children in size(<defunct children>) syscalls instead
+            # of size(<children>): the downside is that this might reap children
+            # which we didn't spawn, which is why we only resort to this when we're
+            # above max_children.
+            while len(self.active_children) >= self.max_children:
+                try:
+                    pid, _ = os.waitpid(-1, 0)
+                    self.active_children.discard(pid)
+                except ChildProcessError:
+                    # we don't have any children, we're done
+                    self.active_children.clear()
+                except OSError:
+                    break
 
-        # If we're above the max number of children, wait and reap them until
-        # we go back below threshold. Note that we use waitpid(-1) below to be
-        # able to collect children in size(<defunct children>) syscalls instead
-        # of size(<children>): the downside is that this might reap children
-        # which we didn't spawn, which is why we only resort to this when we're
-        # above max_children.
-        while len(self.active_children) >= self.max_children:
-            try:
-                pid, _ = os.waitpid(-1, 0)
-                self.active_children.discard(pid)
-            except ChildProcessError:
-                # we don't have any children, we're done
-                self.active_children.clear()
-            except OSError:
-                break
+            # Now reap all defunct children.
+            for pid in self.active_children.copy():
+                try:
+                    pid, _ = os.waitpid(pid, os.WNOHANG)
+                    # if the child hasn't exited yet, pid will be 0 and ignored by
+                    # discard() below
+                    self.active_children.discard(pid)
+                except ChildProcessError:
+                    # someone else reaped it
+                    self.active_children.discard(pid)
+                except OSError:
+                    pass
 
-        # Now reap all defunct children.
-        for pid in self.active_children.copy():
-            try:
-                pid, _ = os.waitpid(pid, os.WNOHANG)
-                # if the child hasn't exited yet, pid will be 0 and ignored by
-                # discard() below
-                self.active_children.discard(pid)
-            except ChildProcessError:
-                # someone else reaped it
-                self.active_children.discard(pid)
-            except OSError:
-                pass
+        def handle_timeout(self):
+            """Wait for zombies after self.timeout seconds of inactivity.
 
-    def handle_timeout(self):
-        """Wait for zombies after self.timeout seconds of inactivity.
+            May be extended, do not override.
+            """
+            self.collect_children()
 
-        May be extended, do not override.
-        """
-        self.collect_children()
+        def service_actions(self):
+            """Collect the zombie child processes regularly in the ForkingMixIn.
 
-    def service_actions(self):
-        """Collect the zombie child processes regularly in the ForkingMixIn.
+            service_actions is called in the BaseServer's serve_forver loop.
+            """
+            self.collect_children()
 
-        service_actions is called in the BaseServer's serve_forver loop.
-        """
-        self.collect_children()
-
-    def process_request(self, request, client_address):
-        """Fork a new subprocess to process the request."""
-        pid = os.fork()
-        if pid:
-            # Parent process
-            if self.active_children is None:
-                self.active_children = set()
-            self.active_children.add(pid)
-            self.close_request(request)
-            return
-        else:
-            # Child process.
-            # This must never return, hence os._exit()!
-            status = 1
-            try:
-                self.finish_request(request, client_address)
-                status = 0
-            except Exception:
-                self.handle_error(request, client_address)
-            finally:
+        def process_request(self, request, client_address):
+            """Fork a new subprocess to process the request."""
+            pid = os.fork()
+            if pid:
+                # Parent process
+                if self.active_children is None:
+                    self.active_children = set()
+                self.active_children.add(pid)
+                self.close_request(request)
+                return
+            else:
+                # Child process.
+                # This must never return, hence os._exit()!
+                status = 1
                 try:
-                    self.shutdown_request(request)
+                    self.finish_request(request, client_address)
+                    status = 0
+                except Exception:
+                    self.handle_error(request, client_address)
                 finally:
-                    os._exit(status)
+                    try:
+                        self.shutdown_request(request)
+                    finally:
+                        os._exit(status)
 
 
 class ThreadingMixIn:

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


More information about the Python-checkins mailing list