-
-
Save pcustic/2e5c5a461a0435f2d24cf870adb01f6d to your computer and use it in GitHub Desktop.
aiolimiter lib example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiolimiter import AsyncLimiter | |
max_requests = 100 | |
time_period = 60 # in seconds | |
limiter = AsyncLimiter(max_requests, time_period) | |
# You can use it with context manager: | |
async with limiter: | |
# This section will, at most, be entered max_requests times / time_period. | |
print("Doing something...") | |
# Or call acquire() method directly. | |
await limiter.acquire() # blocks until there is capacity | |
# Or you can test if there is capacity first. | |
if limiter.has_capacity(): | |
print("Do something") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment