限制 CGI 脚本中 API 的请求速率
我正在编写的脚本有时会向 API 发出请求,而 API 要求将请求限制为每秒最多 1 个。
将 API 请求限制为每秒 1 次的最直接方法是什么?
每次发出请求时是否都会将当前时间存储在文件中?
The script that I'm writing sometimes makes requests to an API and the API requires that requests are limited to a maximum of 1 per second.
What is the most straight forward way of limiting my requests to the API to 1 every second?
Would it involve storing the current time in a file each time a request is made?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为 CGI 调用使用单独的线程,并使用在每次迭代时调用睡眠循环的排队机制。
来自 15.3。时间
You could use a separate thread for the CGI calls and a queuing mechanism that loops with a call to sleep on each iteration.
From 15.3. time
可以在函数一上使用速率限制 python 装饰器希望限制速率,就像 Greg Burek 的这个:
One can use a rate-limiting python decorator on the function one wishes to rate-limit, like this one from Greg Burek: