-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add simple ratelimit control #217
Conversation
khl/requester.py
Outdated
log.debug(f'{method} {route}: req: {params}') # token is excluded | ||
if self.ratelimit: | ||
bucket = self._ratelimit.get_bucket(route) | ||
delay = self._ratelimit.get_delay(bucket) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_delay
中可以内含一个get_bucket
,这样API会更好理解
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delay 是由 bucket 获取的, 不是由 route 获取的 感觉分离比较好
3a63292
to
faf2c3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
晚上我测测看 |
好的,麻烦老师了,我这边测试的时候能稳定住速率 |
add simple ratelimit control
默认启用速率控制(剩余数量小于80时启动),如需禁用则需要Bot传入参数ratelimiter=None
RateLimiter 支持传入参数控制什么时候开始速率控制
当剩余数量(X-Rate-Limit-Remaining) 小于 传入参数时 开始速率控制