rate_limit
multifutures.wait
¶
Wait for wait_time
+ some random jitter
Source code in multifutures/_rate_limit.py
13 14 15 16 17 18 19 20 |
|
multifutures.RateLimit
¶
A wrapper around the limits library. It defaults to using the Moving Window Strategy on the Memory Storage.
Warning
The default strategy only works with multi-threading, not multi-processing. If you want to use it with multiprocessing you need to use a different storage backend (e.g. redis).
Usage¶
rate_limit = RateLimit()
while rate_limit.reached():
wait()
PARAMETER | DESCRIPTION |
---|---|
rate_limit |
The rate limit. An instance of limits.parse. Defaults to 5 requests per seconds.
TYPE:
|
strategy |
The strategy to use. Defaults to a Moving Window using the Memory Storage.
TYPE:
|
Source code in multifutures/_rate_limit.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
reached
¶
Returns True
if the rate limit has been reached, False
otherwise.
RateLimit
instances can be reused in different contexts.
To do so a unique identifier per-context must be provided.
PARAMETER | DESCRIPTION |
---|---|
identifier |
The identifier allows you to reuse the
TYPE:
|
Source code in multifutures/_rate_limit.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|