def main(address):
# Throttle the requests with the BaseThrottler, delaying 1.5s.
bt = BaseThrottler(name='base-throttler', delay=1.5)
# Visit the address provided by the user. Complete URL only.
r = requests.Request(method='GET', url=address)
# 10 requests.
reqs = [r for i in range(0, 10)]
# Submit the requests with the required throttling.
with bt:
throttled_requests = bt.submit(reqs)
# Print the response for each of the requests.
for r in throttled_requests:
print (r.response)
# Final status of the requests.
print ("Success: {s}, Failures: {f}".format(s=bt.successes, f=bt.failures))
11_10_requests_throttling.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录