+14
-6
lines changedFilter options
+14
-6
lines changed Original file line number Diff line number Diff line change
@@ -547,7 +547,7 @@ class ForkingMixIn:
547
547
active_children = None
548
548
max_children = 40
549
549
550
-
def collect_children(self):
550
+
def collect_children(self, *, blocking=False):
551
551
"""Internal routine to wait for children that have exited."""
552
552
if self.active_children is None:
553
553
return
@@ -571,7 +571,8 @@ def collect_children(self):
571
571
# Now reap all defunct children.
572
572
for pid in self.active_children.copy():
573
573
try:
574
-
pid, _ = os.waitpid(pid, os.WNOHANG)
574
+
flags = 0 if blocking else os.WNOHANG
575
+
pid, _ = os.waitpid(pid, flags)
575
576
# if the child hasn't exited yet, pid will be 0 and ignored by
576
577
# discard() below
577
578
self.active_children.discard(pid)
@@ -620,6 +621,10 @@ def process_request(self, request, client_address):
620
621
finally:
621
622
os._exit(status)
622
623
624
+
def server_close(self):
625
+
super().server_close()
626
+
self.collect_children(blocking=True)
627
+
623
628
624
629
class ThreadingMixIn:
625
630
"""Mix-in class to handle each request in a new thread."""
Original file line number Diff line number Diff line change
@@ -144,6 +144,10 @@ def run_server(self, svrcls, hdlrbase, testfunc):
144
144
t.join()
145
145
server.server_close()
146
146
self.assertEqual(-1, server.socket.fileno())
147
+
if HAVE_FORKING and isinstance(server, socketserver.ForkingMixIn):
148
+
# bpo-31151: Check that ForkingMixIn.server_close() waits until
149
+
# all children completed
150
+
self.assertFalse(server.active_children)
147
151
if verbose: print("done")
148
152
149
153
def stream_examine(self, proto, addr):
@@ -371,10 +375,7 @@ def wait_done(self):
371
375
372
376
if HAVE_FORKING:
373
377
class ForkingErrorTestServer(socketserver.ForkingMixIn, BaseErrorTestServer):
374
-
def wait_done(self):
375
-
[child] = self.active_children
376
-
os.waitpid(child, 0)
377
-
self.active_children.clear()
378
+
pass
378
379
379
380
380
381
class SocketWriterTest(unittest.TestCase):
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
+
socketserver.ForkingMixIn.server_close() now waits until all child processes
2
+
completed to prevent leaking zombie processes.
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4