Somewhat nicer handling of errors after thread termination.

This commit is contained in:
Aldo Cortesi 2012-07-10 16:22:45 +12:00
parent ba7437abcb
commit 721e2c8277

View File

@ -213,15 +213,8 @@ class TCPServer:
self.handle_connection(request, client_address) self.handle_connection(request, client_address)
request.close() request.close()
except: except:
try: self.handle_error(request, client_address)
self.handle_error(request, client_address) request.close()
request.close()
# Why a blanket except here? In some circumstances, a thread can
# persist until the interpreter exits. When this happens, all modules
# and builtins are set to None, and things balls up in indeterminate
# ways.
except:
pass
def serve_forever(self, poll_interval=0.1): def serve_forever(self, poll_interval=0.1):
self.__is_shut_down.clear() self.__is_shut_down.clear()
@ -257,10 +250,14 @@ class TCPServer:
""" """
Called when handle_connection raises an exception. Called when handle_connection raises an exception.
""" """
print >> fp, '-'*40 # If a thread has persisted after interpreter exit, the module might be
print >> fp, "Error processing of request from %s:%s"%client_address # none.
print >> fp, traceback.format_exc() if traceback:
print >> fp, '-'*40 exc = traceback.format_exc()
print >> fp, '-'*40
print >> fp, "Error in processing of request from %s:%s"%client_address
print >> fp, exc
print >> fp, '-'*40
def handle_connection(self, request, client_address): # pragma: no cover def handle_connection(self, request, client_address): # pragma: no cover
""" """