SocketServer oversite?

Laurence Tratt tratt at dcs.kcl.ac.uk
Sun May 30 13:48:21 EDT 1999


In SocketServer in the standard library, the method "handle_request" calls
"get_request" thus:

    def handle_request(self):
        """Handle one request, possibly blocking."""
        request, client_address = self.get_request()
        if self.verify_request(request, client_address):
            try:
                self.process_request(request, client_address)
            except:
                self.handle_error(request, client_address)

and get_request is thus defined:

    def get_request(self):
        """Get the request and client address from the socket.

        May be overridden.

        """
        return self.socket.accept()

The problem with this is that socket.accept can throw an error: this then
causes a cascading error throughout the SocketServer, as it's not caught at
any point. In fact, it caused an http server I am involved with to die
completely with some web browsers/platforms/users :)

It would seem to make sense for either handle_request or get_request to do a
try: on this, in order that it won't kill the server. I suspect that the
easiest solution (although not necessarily the best) would be to redo
handle_request along the lines of:

    def handle_request(self):
        """Handle one request, possibly blocking."""
        try:
            request, client_address = self.get_request()
            if self.verify_request(request, client_address):
                self.process_request(request, client_address)
        except:
            self.handle_error(request, client_address)

Of course, I could well be missing the point completely here :)


Laurie




More information about the Python-list mailing list