[Python-checkins] r73878 - python/branches/py3k/Lib/socketserver.py
kristjan.jonsson
python-checkins at python.org
Tue Jul 7 11:09:10 CEST 2009
Author: kristjan.jonsson
Date: Tue Jul 7 11:09:10 2009
New Revision: 73878
Log:
http://bugs.python.org/issue6382
added the shutdown_request() which can perform shutdown before calling close. This is needed for the ForkingMixIn because different close semantics are required for child and parent process. shutdown_request(), for TCP servers, calls socket.shutdown() and then calls close_request(). Therefore, this is not an backwards incompatible change, since subclasses that continue to override close_request() continue to work.
Modified:
python/branches/py3k/Lib/socketserver.py
Modified: python/branches/py3k/Lib/socketserver.py
==============================================================================
--- python/branches/py3k/Lib/socketserver.py (original)
+++ python/branches/py3k/Lib/socketserver.py Tue Jul 7 11:09:10 2009
@@ -168,6 +168,7 @@
- verify_request(request, client_address)
- server_close()
- process_request(request, client_address)
+ - shutdown_request(request)
- close_request(request)
- handle_error()
@@ -281,7 +282,7 @@
self.process_request(request, client_address)
except:
self.handle_error(request, client_address)
- self.close_request(request)
+ self.shutdown_request(request)
def handle_timeout(self):
"""Called if no new request arrives within self.timeout.
@@ -305,7 +306,7 @@
"""
self.finish_request(request, client_address)
- self.close_request(request)
+ self.shutdown_request(request)
def server_close(self):
"""Called to clean-up the server.
@@ -319,6 +320,10 @@
"""Finish one request by instantiating RequestHandlerClass."""
self.RequestHandlerClass(request, client_address, self)
+ def shutdown_request(self, request):
+ """Called to shutdown and close an individual request."""
+ self.close_request(request)
+
def close_request(self, request):
"""Called to clean up an individual request."""
pass
@@ -359,6 +364,7 @@
- handle_timeout()
- verify_request(request, client_address)
- process_request(request, client_address)
+ - shutdown_request(request)
- close_request(request)
- handle_error()
@@ -443,14 +449,18 @@
"""
return self.socket.accept()
- def close_request(self, request):
- """Called to clean up an individual request."""
+ def shutdown_request(self, request):
+ """Called to shutdown and close an individual request."""
try:
#explicitly shutdown. socket.close() merely releases
#the socket and waits for GC to perform the actual close.
request.shutdown(socket.SHUT_WR)
except socket.error:
pass #some platforms may raise ENOTCONN here
+ self.close_request(request)
+
+ def close_request(self, request):
+ """Called to clean up an individual request."""
request.close()
@@ -472,6 +482,10 @@
# No need to call listen() for UDP.
pass
+ def shutdown_request(self, request):
+ # No need to shutdown anything.
+ self.close_request(request)
+
def close_request(self, request):
# No need to close anything.
pass
@@ -539,10 +553,12 @@
# This must never return, hence os._exit()!
try:
self.finish_request(request, client_address)
+ self.shutdown_request(request)
os._exit(0)
except:
try:
self.handle_error(request, client_address)
+ self.shutdown_request(request)
finally:
os._exit(1)
@@ -562,10 +578,10 @@
"""
try:
self.finish_request(request, client_address)
- self.close_request(request)
+ self.shutdown_request(request)
except:
self.handle_error(request, client_address)
- self.close_request(request)
+ self.shutdown_request(request)
def process_request(self, request, client_address):
"""Start a new thread to process the request."""
More information about the Python-checkins
mailing list