-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d993841
commit 9d0e4a3
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from ratelimiter import RateLimiter | ||
|
||
@RateLimiter(max_calls=1, period=1) | ||
def foo(i): | ||
print(i) | ||
|
||
@RateLimiter(max_calls=5, period=10) | ||
def bar(i): | ||
foo(i) | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
|
||
# with decorator: | ||
for i in range(100): | ||
bar(i) | ||
|
||
# with context: | ||
rate_limiter1 = RateLimiter(max_calls=1, period=1) | ||
rate_limiter2 = RateLimiter(max_calls=5, period=10) | ||
|
||
for i in range(100): | ||
with rate_limiter1: | ||
with rate_limiter2: | ||
print(i) |