summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-07-28 21:39:28 (GMT)
committerGuido van Rossum <guido@python.org>1999-07-28 21:39:28 (GMT)
commit2ab455a8fa946cb8d599018c2f861f1fe909c545 (patch)
tree87b146463fedcd8c9ebfacf5607213da864bad8d /Lib
parentddc469679bb79e38605f6ad65c88c83a29def5ce (diff)
downloadcpython-2ab455a8fa946cb8d599018c2f861f1fe909c545.zip
cpython-2ab455a8fa946cb8d599018c2f861f1fe909c545.tar.gz
cpython-2ab455a8fa946cb8d599018c2f861f1fe909c545.tar.bz2
Another patch from Andy Dustman:
""" 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.)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/SocketServer.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py
index 82bc8fb..f7da84f 100644
--- a/Lib/SocketServer.py
+++ b/Lib/SocketServer.py
@@ -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