开发者

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:

  1. The class derived from SocketServer.BaseRequestHandler should be MyUDPServerHandler or something else, but should not be UDPServer which is a built-in class in SocketServer
  2. It should be server = SocketServer.UDPServer(('localhost', '12345'), MyUDPServerhandler)
  3. Then maybe it should be server.timeout = .500. And define a handle_timeout() method
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜