Throttler for asyncio Python
Project description
aiothrottler
Throttler for asyncio Python
Installation
pip install aiothrottler
Example: multiple tasks throttled
import asyncio
import time
from aiothrottler import Throttler
async def main():
throttler = Throttler(0.5)
await asyncio.gather(*[
worker(throttler) for _ in range(10)
])
async def worker(throttler):
await throttler()
# Interval of at least 0.5 seconds between prints
# even though all workers started together
print(time.time())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
Example: single task throttled/smoothed
import asyncio
import random
import time
from aiothrottler import Throttler
async def main():
throttler = Throttler(0.5)
for _ in range(10):
await throttler()
# Interval of at least 0.5 seconds between prints
# even though each sleep is random
print(time.time())
await asyncio.sleep(random.random())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiothrottler-0.0.3.tar.gz
(2.0 kB
view hashes)
Built Distribution
Close
Hashes for aiothrottler-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24ec76fe700eddb1e32e8230a8f067ec13675e1bd54c031c39a53863e38eb219 |
|
MD5 | a3eedc9b919f5f7e9ec68002a93a7db1 |
|
BLAKE2b-256 | 2036b69516ed973b29427142039d99eda24db5760bb6f7a906706e46733099ca |