summaryrefslogtreecommitdiffstats
path: root/Lib/SocketServer.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-02-28 20:02:27 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-02-28 20:02:27 (GMT)
commit70e7ea23f18aacc31f429787645ff8c074c0ad86 (patch)
treebeb83e14c2f9fdd729914234d9979b50a70718c3 /Lib/SocketServer.py
parent9e7f1d2e965400edcb2c0cb7fee625ef2b595eb5 (diff)
downloadcpython-70e7ea23f18aacc31f429787645ff8c074c0ad86.zip
cpython-70e7ea23f18aacc31f429787645ff8c074c0ad86.tar.gz
cpython-70e7ea23f18aacc31f429787645ff8c074c0ad86.tar.bz2
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61097,61103-61108 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r61105 | andrew.kuchling | 2008-02-28 15:03:03 +0100 (Thu, 28 Feb 2008) | 1 line #2169: make generated HTML more valid ........ r61106 | jeffrey.yasskin | 2008-02-28 19:03:15 +0100 (Thu, 28 Feb 2008) | 4 lines Prevent SocketServer.ForkingMixIn from waiting on child processes that it didn't create, in most cases. When there are max_children handlers running, it will still wait for any child process, not just handler processes. ........ r61107 | raymond.hettinger | 2008-02-28 20:41:24 +0100 (Thu, 28 Feb 2008) | 1 line Document impending updates to itertools. ........ r61108 | martin.v.loewis | 2008-02-28 20:44:22 +0100 (Thu, 28 Feb 2008) | 1 line Add 2.6aN uuids. ........
Diffstat (limited to 'Lib/SocketServer.py')
-rw-r--r--Lib/SocketServer.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py
index 9c5d4c2..47d8728 100644
--- a/Lib/SocketServer.py
+++ b/Lib/SocketServer.py
@@ -440,18 +440,30 @@ class ForkingMixIn:
def collect_children(self):
"""Internal routine to wait for children that have exited."""
- 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
+ if self.active_children is None: return
+ while len(self.active_children) >= self.max_children:
+ # XXX: This will wait for any child process, not just ones
+ # spawned by this library. This could confuse other
+ # libraries that expect to be able to wait for their own
+ # children.
try:
- pid, status = os.waitpid(0, options)
+ pid, status = os.waitpid(0, options=0)
except os.error:
pid = None
- if not pid: break
+ if pid not in self.active_children: continue
+ self.active_children.remove(pid)
+
+ # XXX: This loop runs more system calls than it ought
+ # to. There should be a way to put the active_children into a
+ # process group and then use os.waitpid(-pgid) to wait for any
+ # of that set, but I couldn't find a way to allocate pgids
+ # that couldn't collide.
+ for child in self.active_children:
+ try:
+ pid, status = os.waitpid(child, os.WNOHANG)
+ except os.error:
+ pid = None
+ if not pid: continue
try:
self.active_children.remove(pid)
except ValueError as e: