Skip to main content

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


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)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page