]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Another patch from Andy Dustman:
authorGuido van Rossum <guido@python.org>
Wed, 28 Jul 1999 21:39:28 +0000 (21:39 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 28 Jul 1999 21:39:28 +0000 (21:39 +0000)
"""
Here's a patch for the ForkingMixIn which will prevent the server from
forking itself into the ground. Note: I've tested a very similar patch
(subclassed ForkingMixIn) but not actually tested this one. As you might
surmise, this was done out of necessity...

If the maximum number of children are already running, block while waiting
for a child to exit.
"""

(I added that last sentence as a comment to the code --GvR.)

Lib/SocketServer.py

index 82bc8fb7a28479bb1ec8fa7ddc6da19f21a6f8bb..f7da84f5575a1fa28fb1c60cf68679f0565584bd 100644 (file)
@@ -281,12 +281,19 @@ class ForkingMixIn:
     """Mix-in class to handle each request in a new process."""
 
     active_children = None
+    max_children = 40
 
     def collect_children(self):
         """Internal routine to wait for died children."""
         while self.active_children:
+            if len(self.active_children) < self.max_children:
+                options = os.WNOHANG
+            else:
+                # If the maximum number of children are already
+                # running, block while waiting for a child to exit
+                options = 0
             try:
-                pid, status = os.waitpid(0, os.WNOHANG)
+                pid, status = os.waitpid(0, options)
             except os.error:
                 pid = None
             if not pid: break