Apply an async function to each item in an array or queue with limited concurrency
Project description
aioeachlimit
Apply an async function to each item in an array or queue with limited concurrency
Install
pip install aioeachlimit
Usage
async def f(item):
asyncio.sleep(3)
return item * 2
items = [1, 2, 3, 4]
async for result in aioeachlimit(items, f, concurrency_limit=2):
print(result) # Prints 2 4 6 8 in random order
If you don't need to return anything:
await aioeachlimit(items, f, concurrency_limit=2, discard_results=True)
If items
is an asyncio.Queue
then aioeachlimit will read from it indefinitely.
Tests
pytest .
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
aioeachlimit-0.1.0.tar.gz
(2.4 kB
view hashes)