Delaying requests instead of failing #150
-
Hello, from pyrate_limiter import Duration, Limiter, Rate
GLOBAL_THROTTLE = Duration.MINUTE * 5
GLOBAL_LIMITER = Limiter(
[
# request stuff slowly, like a human
Rate(1, Duration.SECOND * 1),
# take breaks when requesting stuff, like a human
Rate(40, GLOBAL_THROTTLE),
],
max_delay=GLOBAL_THROTTLE + 500,
)
global_limiter_decorator = GLOBAL_LIMITER.as_decorator()
def mapping(*args, **kwargs):
return ("moddb", 1)
def ratelimit(func):
return global_limiter_decorator(mapping)(func)
@ratelimit
def ratelimited_function(x):
print(x)
def test_ratelimit():
for x in range(41):
ratelimited_function(x)
if __name__ == "__main__":
test_ratelimit() What I expect to happen is that a number will be printed every second until it hits 39 (which would be the 40th call). On the 41st call the library will check to see how much time is required to sleep, which should be 5 minutes. The library then sees that the max delay is set to 5 minutes + 0.5 seconds which is more. Therefore, the library sleeps for 5 minutes and then retries the 41st call which print successfully. What I instead see is that on the 41st call the following error happens
Could someone help me understand where in my assumptions I am going wrong. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In the end I decided to move to my own implementation. |
Beta Was this translation helpful? Give feedback.
In the end I decided to move to my own implementation.