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 details)

Uploaded Source

File details

Details for the file aioeachlimit-0.1.0.tar.gz.

File metadata

  • Download URL: aioeachlimit-0.1.0.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.1 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.7.2

File hashes

Hashes for aioeachlimit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5cace907ee476f0cb579d4d8a5a29034f472cc4c8b98604f8664b63368b9a0ca
MD5 f527cbf31710fe06d780a303919880d7
BLAKE2b-256 7ce210765b5f87959d19548c06c752026fdd5de35ce2086627dd16a53b5a1099

See more details on using hashes here.

Supported by

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