Exception Handling in TCPServer (was; Problem exiting application in Windows Console.)
Matimus
mccredie at gmail.com
Wed Nov 8 14:16:10 EST 2006
> This seems a really nasty hack though - any ideas for a cleaner way to
> do it?
You could overload handle_request instead. I think that makes more
sense anyway because you don't want to handle a SystemExit exception as
an error, you want to exit. Of course this only deals with catching the
exception, there may be a better method of shutting down and exiting
the server (other than sys.exit that is).
class HelpServer(HTTPServer):
def handle_request(self):
try:
request, client_address = self.get_request()
except socket.error:
return
if self.verify_request(request, client_address):
try:
self.process_request(request, client_address)
except SystemExit:
raise SystemExit
except:
self.handle_error(request, client_address)
self.close_request(request)
More information about the Python-list
mailing list