【发布时间】:2017-09-20 10:30:46
【问题描述】:
目前使用的 API 将我的速率限制为每 10 秒 3000 个请求。由于 Tornado 的异步 IO 特性,我有 10,000 个使用 Tornado 获取的 url。
如何实施速率限制以反映 API 限制?
from tornado import ioloop, httpclient
i = 0
def handle_request(response):
print(response.code)
global i
i -= 1
if i == 0:
ioloop.IOLoop.instance().stop()
http_client = httpclient.AsyncHTTPClient()
for url in open('urls.txt'):
i += 1
http_client.fetch(url.strip(), handle_request, method='HEAD')
ioloop.IOLoop.instance().start()
【问题讨论】:
标签: python httprequest tornado rate-limiting