◐ Shell
clean mode source ↗

bpo-31151: Add socketserver.ForkingMixIn.server_close() by vstinner · Pull Request #3057 · python/cpython

Expand Up @@ -547,7 +547,7 @@ class ForkingMixIn: active_children = None max_children = 40
def collect_children(self): def collect_children(self, *, blocking=False): """Internal routine to wait for children that have exited.""" if self.active_children is None: return Expand All @@ -571,7 +571,8 @@ def collect_children(self): # Now reap all defunct children. for pid in self.active_children.copy(): try: pid, _ = os.waitpid(pid, os.WNOHANG) flags = 0 if blocking else os.WNOHANG pid, _ = os.waitpid(pid, flags) # if the child hasn't exited yet, pid will be 0 and ignored by # discard() below self.active_children.discard(pid) Expand Down Expand Up @@ -620,6 +621,10 @@ def process_request(self, request, client_address): finally: os._exit(status)
def server_close(self): super().server_close() self.collect_children(blocking=True)

class ThreadingMixIn: """Mix-in class to handle each request in a new thread.""" Expand Down