diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-10-29 10:44:59 +0300 |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-10-29 10:44:59 +0300 |
commit | f54f3afb9fa8358081a0cf303c102f1a7c4df9e9 (patch) | |
tree | 5229ef1e2f6d02da457ed19649a7cd59c32c1f77 /Lib/socketserver.py | |
parent | f2b46973fe247fe0d8f431693b4f8409737935cd (diff) | |
parent | 6861a53904441e10f1829c3756d18cf014698b3e (diff) | |
download | cpython-f54f3afb9fa8358081a0cf303c102f1a7c4df9e9.tar.gz |
#13289: merge with 3.2.
Diffstat (limited to 'Lib/socketserver.py')
-rw-r--r-- | Lib/socketserver.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/socketserver.py b/Lib/socketserver.py index 0e2ba83d1d..0d217ed3b5 100644 --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -170,6 +170,7 @@ class BaseServer: - process_request(request, client_address) - shutdown_request(request) - close_request(request) + - service_actions() - handle_error() Methods for derived classes: @@ -225,6 +226,8 @@ class BaseServer: r, w, e = select.select([self], [], [], poll_interval) if self in r: self._handle_request_noblock() + + self.service_actions() finally: self.__shutdown_request = False self.__is_shut_down.set() @@ -239,6 +242,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: # @@ -539,9 +550,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 @@ -549,6 +566,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()! |