asyncio-pool-ng
About
AsyncioPoolNG takes the ideas used in asyncio-pool and wraps them around an asyncio.TaskGroup.
AsyncioPool has three main functions spawn, map, and itermap.
spawn: Schedule an async function on the pool and get a future back which will eventually have either the result or the exception from the function.map: Spawn an async function for each item in an iterable object, and return a set containing a future for each item.
asyncio.wait()can be used to wait for the set of futures to complete.- When the
AsyncioPoolcloses, it will wait for all tasks to complete. All pending futures will be complete once it is closed.
itermap: Works similarly tomapbut returns an Async Generator which yields each future as it completes.
Differences from asyncio-pool
asyncio-pool-ngimplements Python typing and passes validation checks with mypy's strict mode. This helps IDEs and static type checkers know what type of result to expect when getting data from a completed future.asyncio-pooluses callbacks to process data before returning it;asyncio-pool-ngonly returns Future instances directly. The future will contain either a result or an exception which can then be handled as needed.- While
asyncio-poolschedules Coroutine instances directly,asyncio-pool-ngtakes the callable and arguments, and creates the Coroutine instance at execution time.
Example
import asyncio
import logging
from random import random
from asyncio_pool import AsyncioPool
logging.basicConfig(level=logging.INFO)
async def worker(number: int) -> int:
await asyncio.sleep(random() / 2)
return number * 2
async def main() -> None:
result: int = 0
results: list[int] = []
async with AsyncioPool(2) as pool:
"""spawn task and wait for the results"""
result = await pool.spawn(worker, 5)
assert result == 10
logging.info(f"results for pool.spawn(worker, 5): {result}")
"""spawn task and get results later"""
future: asyncio.Future[int] = pool.spawn(worker, 5)
# do other stuff
result = await future
assert result == 10
"""map an async function to a set of values"""
futures: set[asyncio.Future[int]] = pool.map(worker, range(10))
await asyncio.wait(futures)
results = [x.result() for x in futures]
logging.info(f"results for pool.map(worker, range(10)): {results}")
results.sort()
assert results == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
"""iterate futures as they complete"""
logging.info("results for pool.itermap(worker, range(10)):")
results = []
async for future in pool.itermap(worker, range(10)):
results.append(future.result())
logging.info(f"> {future.result()}")
results.sort()
assert results == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
asyncio.run(main())
Metadata
Release files for asyncio-pool-ng 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| asyncio_pool_ng-0.9.0.tar.gz | 55.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asyncio_pool_ng-0.9.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.7 kB
Release files / asyncio_pool_ng-0.9.0.tar.gz
| Download URL | asyncio_pool_ng-0.9.0.tar.gz |
|---|---|
| Size | 55.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba9379b25280095193346d4bc518d898c40d0b58a1e0ef2ca5b93699cf69d9ad
|
|
BLAKE2b-256 checksum How to use checksums |
786620d8fc62bd577b9e5f06d91b1d02e764d33b06e1b39b2b1d876a7c91d808
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / asyncio_pool_ng-0.9.0-py3-none-any.whl
| Download URL | asyncio_pool_ng-0.9.0-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6289f7472c3b87d84a883fe61801b6e08da971a05a45278c4c3751d13c033f52
|
|
BLAKE2b-256 checksum How to use checksums |
b6b898a8487fdc595cba440d0dcee4ae3e9e3d0d6572aec5e295977d20dcb4f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for asyncio-pool-ng 0.9.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.