From 83c3281826316e2a1c1e9b682c5d303be5df79f4 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 23 Oct 2001 21:42:45 +0000 Subject: =?UTF-8?q?Apply=20the=20first=20chunk=20of=20the=20second=20patch?= =?UTF-8?q?=20from=20SF=20bug=20#471720:=20ThreadingMixIn/TCPServer=20forg?= =?UTF-8?q?ets=20close=20(Max=20Neunh=C3=B6ffer).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures that handle_error() and close_request() are called when an error occurs in the thread. (I am not applying the second chunk of the patch, which moved the finish() call into the finally clause in BaseRequestHandler's __init__ method; that would be a semantic change that I cannot accept at this point - the data would be sent even if the handler raised an exception.) --- Lib/SocketServer.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py index 5128e17..7e1e27c 100644 --- a/Lib/SocketServer.py +++ b/Lib/SocketServer.py @@ -449,9 +449,17 @@ class ThreadingMixIn: """Mix-in class to handle each request in a new thread.""" def process_request_thread(self, request, client_address): - """Same as in BaseServer but as a thread.""" - self.finish_request(request, client_address) - self.close_request(request) + """Same as in BaseServer but as a thread. + + In addition, exception handling is done here. + + """ + try: + self.finish_request(request, client_address) + self.close_request(request) + except: + self.handle_error(request, client_address) + self.close_request(request) def process_request(self, request, client_address): """Start a new thread to process the request.""" -- cgit v0.12