summaryrefslogtreecommitdiffstats
path: root/Lib/socketserver.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/socketserver.py')
-rw-r--r--Lib/socketserver.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index f8e87e6..2f39514 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -127,6 +127,7 @@ import socket
import selectors
import os
import errno
+import sys
try:
import threading
except ImportError:
@@ -311,9 +312,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)
@@ -367,12 +371,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):
@@ -596,16 +600,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:
@@ -623,9 +628,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):