|
1 | | -# Implementation of Token Bucket Algorithm |
2 | | -# Token `rate` is added to the bucket every `frequency` in seconds. |
3 | | -# The bucket can hold tokens up to `capacity` (full). |
4 | | -# The bucket starts full. |
5 | | -# Each request consume one token. |
6 | | -# If a token arrives when the bucket is full, token is discarded. |
7 | | -# If a request arrives when bucket is empty, request will be discarded. |
8 | | -# If bucket has tokens available, requests will pass. |
9 | | -# https://en.wikipedia.org/wiki/Token_bucket |
| 1 | +""" |
| 2 | +Implementation of the Token Bucket Algorithm |
| 3 | +Token `rate` is added to the bucket every `frequency` seconds. |
| 4 | +The bucket can hold tokens up to `capacity` (full). |
| 5 | +The bucket starts full. |
| 6 | +Each request consumes one token. |
| 7 | +If a token arrives when the bucket is full, the token is discarded. |
| 8 | +If a request arrives when the bucket is empty, it is discarded. |
| 9 | +If the bucket has tokens available, requests will pass. |
| 10 | +https://en.wikipedia.org/wiki/Token_bucket |
| 11 | +""" |
| 12 | + |
10 | 13 | import threading |
11 | 14 | import time |
12 | 15 |
|
@@ -38,7 +41,7 @@ def _add_tokens(self) -> None: |
38 | 41 | """ |
39 | 42 | Refill tokens only when a full minute has passed. |
40 | 43 | >>> bucket = TokenBucketRateLimiter(1, 4, 60) |
41 | | - >>> bucket.tokens # Initially has 4 token (rate) |
| 44 | + >>> bucket.tokens # Initially has a rate of 4 tokens |
42 | 45 | 4 |
43 | 46 | >>> bucket._add_tokens() |
44 | 47 | >>> bucket.tokens # Bucket already full |
|
0 commit comments