0
目前使用的API速率限制了我每10秒3000個請求。由於具有異步IO特性,我有10,000個使用Tornado獲取的網址。Python旋風速率限制AsyncHttpClient獲取
我該如何去執行速率限制以反映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()