How to kill a SocketServer?

Guido van Rossum gvanrossum at gmail.com
Mon May 2 13:25:55 EDT 2005


[Skip Montanaro]

> I stumbled on a somewhat cleaner way to do this using socket timeouts:
> 
>     class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
>         pause = 0.25
>         allow_reuse_address = True
> 
>         def __init__(self, server_address, RequestHandlerClass):
>             SocketServer.TCPServer.__init__(self, server_address,
>                                             RequestHandlerClass)
>             self.socket.settimeout(self.pause)
>             self.serving = 1
>             ...
> 
>         def serve_forever(self):
>             while self.serving:
>                 self.handle_request()
> 
> As far as my simple testing went (a trivial little xmlrpc server exposing
> only "noop" and "exit" methods), the above worked fine.  I was mildly
> surprised that I didn't have to catch socket.timeout exceptions.

I think this would cause timeouts in the middle of handling request
whenever a client is slow.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list