Skip to content

Commit 4145400

Browse files
authored
Update comments for clarity in token_bucket.py
1 parent c831eee commit 4145400

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

‎other/token_bucket.py‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
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+
1013
import threading
1114
import time
1215

@@ -38,7 +41,7 @@ def _add_tokens(self) -> None:
3841
"""
3942
Refill tokens only when a full minute has passed.
4043
>>> bucket = TokenBucketRateLimiter(1, 4, 60)
41-
>>> bucket.tokens # Initially has 4 token (rate)
44+
>>> bucket.tokens # Initially has a rate of 4 tokens
4245
4
4346
>>> bucket._add_tokens()
4447
>>> bucket.tokens # Bucket already full

0 commit comments

Comments
 (0)