Bug? causing rate limit to not be applied as expected
Closed this issue · 1 comments
Adam-D-Lewis commented
I would expect the following code to add 10 items to the indices_added list, but only 6 are added. This seems like a bug.
import time
from pyrate_limiter import Duration, Rate, InMemoryBucket, Limiter, BucketFullException
rates = [Rate(1, Duration.SECOND*1/10)]
basic_bucket = InMemoryBucket(rates)
limiter = Limiter(basic_bucket)
indices_added = []
for index in range(10):
try:
time.sleep(0.1)
limiter.try_acquire(index)
indices_added.append(index)
except BucketFullException:
pass
print(len(indices_added))
# 6
print(indices_added)
# [0, 2, 4, 5, 7, 9]
vutran1710 commented
when interval is too small, some tolerance must be considered because of computation and stuffs.
can u try sleep(0.105) or 0.11?