Closed firmianay closed 1 year ago
Oops, my bad. Fixing now
fixed in 3.0.2
Thanks! I found that this version has changed a lot. My previous code looks like this. How can I modify it?
def send(self, text_list: list):
limiter = Limiter(RequestRate(20, Duration.MINUTE))
for text in text_list:
with limiter.ratelimit('identity', delay=True):
...
r = requests.post(url=url, headers=headers, data=json.dumps(data))
Oh you can change it into something like this
from pyrate_limiter import Duration, Rate, InMemoryBucket, Limiter
rates = [Rate(20, Duration.MINUTE)]
bucket = InMemoryBucket(rates)
# lets say you want to delay until it can consume, the max-delay can be set to equal the rate's interval
limiter = Limiter(bucket, max_delay=Duration.MINUTE.value)
for text in text_lists:
limiter.try_acquire('identity')
r = requests.post(...)
It worked, thanks
I use pip to install pyrate-limiter.