diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
commit | ea7bc055b08fb442986e0735b1b5b325b0b51ecc (patch) | |
tree | 20c2b837c787daf7e95ece075e6544627b17625a /Lib/socketserver.py | |
parent | c32365d2ce552d1d17279e30a564509235ffb1db (diff) | |
parent | c2c9c905706160bf34aea12f2348210aac3e0da2 (diff) | |
download | cpython-ea7bc055b08fb442986e0735b1b5b325b0b51ecc.tar.gz |
Merge #14399: corrected news item
Diffstat (limited to 'Lib/socketserver.py')
-rw-r--r-- | Lib/socketserver.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/Lib/socketserver.py b/Lib/socketserver.py index adf9f38ead..261e28e641 100644 --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -153,8 +153,8 @@ def _eintr_retry(func, *args): while True: try: return func(*args) - except (OSError, select.error) as e: - if e.args[0] != errno.EINTR: + except OSError as e: + if e.errno != errno.EINTR: raise class BaseServer: @@ -180,6 +180,7 @@ class BaseServer: - process_request(request, client_address) - shutdown_request(request) - close_request(request) + - service_actions() - handle_error() Methods for derived classes: @@ -236,6 +237,8 @@ class BaseServer: poll_interval) if self in r: self._handle_request_noblock() + + self.service_actions() finally: self.__shutdown_request = False self.__is_shut_down.set() @@ -250,6 +253,14 @@ class BaseServer: self.__shutdown_request = True self.__is_shut_down.wait() + def service_actions(self): + """Called by the serve_forever() loop. + + May be overridden by a subclass / Mixin to implement any code that + needs to be run during the loop. + """ + pass + # The distinction between handling, getting, processing and # finishing a request is fairly arbitrary. Remember: # @@ -550,9 +561,15 @@ class ForkingMixIn: """ self.collect_children() + def service_actions(self): + """Collect the zombie child processes regularly in the ForkingMixin. + + service_actions is called in the BaseServer's serve_forver loop. + """ + self.collect_children() + def process_request(self, request, client_address): """Fork a new subprocess to process the request.""" - self.collect_children() pid = os.fork() if pid: # Parent process @@ -560,6 +577,7 @@ class ForkingMixIn: self.active_children = [] self.active_children.append(pid) self.close_request(request) + return else: # Child process. # This must never return, hence os._exit()! |