Skip to content

Commit

Permalink
add rate limit example
Browse files Browse the repository at this point in the history
  • Loading branch information
vuchetichbalint committed Nov 2, 2017
1 parent d993841 commit 9d0e4a3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions process_management/rate_limiting.py
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)

0 comments on commit 9d0e4a3

Please sign in to comment.