2

我有这部分代码:

como_url = "".join(['http://', options.como_address, ':', options.como_port, 
                        '/ztc_config?netid=0&opcode_group=0&opcode=0&start=-20s&end=-1s'])

http_client = AsyncHTTPClient()
response = yield tornado.gen.Task(http_client.fetch, como_url)

我在哪里做一个http请求。我会添加一个连接超时,以确保前面的代码被执行,所以我可以找到我的响应。

如何添加超时?我必须将它添加到 tornado.gen.Task 调用中吗?我不知道该怎么做。

4

2 回答 2

4

使用HTTPRequest该类为请求添加超时,而不是仅将 url 传递给fetch. 尝试:

request = tornado.httpclient.HTTPRequest(url=como_url, connect_timeout=20.0, request_timeout=20.0)
response = yield tornado.gen.Task(http_client.fetch, request)

http://www.tornadoweb.org/en/branch2.4/httpclient.html#tornado.httpclient.HTTPRequest

于 2013-03-12T15:07:02.390 回答
3

我也遇到过这个问题,有时超时不起作用。原因是SimpleAsyncHTTPClient.max_clients达到最大值。

SimpleAsyncHTTPClient.fetch_impl中,如果数量self.active大于数量,max_clients则不timeout_handle分配。

所以你添加增加龙卷风实例或者max_clients,可以解决它

于 2017-03-23T05:21:47.737 回答