Rate Limit
- hivecore.decorator.rate_limited(max_per_second: int, period: int | float = 1) any
A decorator that limits the amount of times you can call a function.
- Parameters:
max_per_second (int) – Max number of runs per second.
period (Optional[Union[int, float]], optional) – Time between runs, in seconds. Default to 1.
- Returns:
The result from the function execution.
- Return type:
Any
Example
from hivecore.decorator import rate_limited
import random
@rate_limited(2, 5)
def random_value():
value = random.randint(1, 5)
print(value)
if value == 3:
pass
#raise ValueError("Value cannot be 3")
return value