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.9.tar.gz
(1.9 kB
view hashes)
Built Distribution
Close
Hashes for aiothrottler-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f280ab6d9e0b69f424c660f2bd73a07aed0dd1bb13281e5f81f4d1a8cc0cc55 |
|
MD5 | 8a5d6e86b96957cf18bbad4c571cc176 |
|
BLAKE2b-256 | 60122a784affe18850d052f09124db7df40e05cfa091e7b1f94266c2957f44e8 |