limits
limits copied to clipboard
How do you block until the rate has capacity?
Came here from Justin Van Winkle's survey of Python rate limiters. He said limits "seems to work", which is high praise because the rest were somehow broken.
Am I missing something with the hit
function?
Quickstart shows how to assert whether it returns True
or False
and to sleep to make a previous False
turn True
.
assert True == moving_window.hit(one_per_minute, "test_namespace", "foo")
assert False == moving_window.hit(one_per_minute, "test_namespace", "foo")
assert True == moving_window.hit(one_per_minute, "test_namespace", "bar")
assert True == moving_window.hit(one_per_second, "test_namespace", "foo")
assert False == moving_window.hit(one_per_second, "test_namespace", "foo")
time.sleep(1)
assert True == moving_window.hit(one_per_second, "test_namespace", "foo")
I want a rate limiter that blocks until the request would satisfy the limit; that is, as soon as hit
would return True
.
I suppose I could built something like that using hit
, but I don't want to. If I have to start writing sleeps into my code, then I think there's something missing from my rate limiter library.