diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-02-21 08:49:56 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-02-21 08:49:56 (GMT) |
commit | d9108d1253eef9f43c60e0ed5f1ec5603c1fba6c (patch) | |
tree | aa46f7db962e856b6a9fbc2845972ceaccfcf8eb /Lib/socketserver.py | |
parent | 86a8be00ed5266550a3d97a3c065f7a22018b6a6 (diff) | |
download | cpython-d9108d1253eef9f43c60e0ed5f1ec5603c1fba6c.zip cpython-d9108d1253eef9f43c60e0ed5f1ec5603c1fba6c.tar.gz cpython-d9108d1253eef9f43c60e0ed5f1ec5603c1fba6c.tar.bz2 |
Issue #23430: Stop socketserver from catching SystemExit etc from handlers
Also make handle_error() consistently output to stderr, and fix the
documentation.
Diffstat (limited to 'Lib/socketserver.py')
-rw-r--r-- | Lib/socketserver.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/Lib/socketserver.py b/Lib/socketserver.py index 1524d16..64689991 100644 --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -132,6 +132,7 @@ import socket import selectors import os import errno +import sys try: import threading except ImportError: @@ -316,9 +317,12 @@ class BaseServer: if self.verify_request(request, client_address): try: self.process_request(request, client_address) - except: + except Exception: self.handle_error(request, client_address) self.shutdown_request(request) + except: + self.shutdown_request(request) + raise else: self.shutdown_request(request) @@ -372,12 +376,12 @@ class BaseServer: The default is to print a traceback and continue. """ - print('-'*40) - print('Exception happened during processing of request from', end=' ') - print(client_address) + print('-'*40, file=sys.stderr) + print('Exception happened during processing of request from', + client_address, file=sys.stderr) import traceback - traceback.print_exc() # XXX But this goes to stderr! - print('-'*40) + traceback.print_exc() + print('-'*40, file=sys.stderr) class TCPServer(BaseServer): @@ -601,16 +605,17 @@ class ForkingMixIn: else: # Child process. # This must never return, hence os._exit()! + status = 1 try: self.finish_request(request, client_address) - self.shutdown_request(request) - os._exit(0) - except: + status = 0 + except Exception: + self.handle_error(request, client_address) + finally: try: - self.handle_error(request, client_address) self.shutdown_request(request) finally: - os._exit(1) + os._exit(status) class ThreadingMixIn: @@ -628,9 +633,9 @@ class ThreadingMixIn: """ try: self.finish_request(request, client_address) - self.shutdown_request(request) - except: + except Exception: self.handle_error(request, client_address) + finally: self.shutdown_request(request) def process_request(self, request, client_address): |