How do I set the timeout of a SocketServer in Python?
I want to use server.get_request()
to receive requests, but I want it to timeout after 500 milliseco开发者_如何学Gonds. Is this correct? Doesn't seem to work... thanks.
class UDPServer(SocketServer.BaseRequestHandler):
timeout = .500
if __name__ == "__main__":
server = SocketServer.UDPServer(('localhost', '12345'), UDPServer)
server.get_request()
I feel there are some places wrong:
- The class derived from
SocketServer.BaseRequestHandler
should beMyUDPServerHandler
or something else, but should not be UDPServer which is a built-in class in SocketServer - It should be
server = SocketServer.UDPServer(('localhost', '12345'), MyUDPServerhandler)
- Then maybe it should be
server.timeout = .500
. And define ahandle_timeout()
method
精彩评论