asyncio-pool is a Python library that provides a pool for asyncio coroutines, offering a familiar interface similar to `multiprocessing.Pool`. It ensures that a controlled number of coroutines are active concurrently, managing task scheduling and results. The current version is 0.6.0, released in May 2022, with a stalled release cadence but remains functional.
pip install asyncio-poolVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create an `AioPool`, use its `map` method to process an iterable of items concurrently, and individually `spawn` coroutines. The `async with` statement ensures the pool is properly shut down and all tasks are awaited.
Review usage of `spawn_n` and `map_n` to ensure they align with the new synchronous spawning model. For very large numbers of tasks, consider the `itermap` method or manual `spawn` with explicit result collection to manage memory more efficiently.
For massive workloads, consider breaking down the iterable into smaller chunks or implementing a custom producer-consumer pattern with a queue to limit the number of active coroutine objects at any given time. Continuously monitor memory usage for large-scale applications.
Always ensure that any coroutine object you create is either `await`ed immediately, passed to an `AioPool` method (e.g., `pool.spawn(my_coroutine())`), or scheduled using `asyncio.create_task()`.
If `my_async_function` is intended to run as part of the pool, pass its result (the coroutine object) to a pool method, e.g., `future = pool.spawn(my_async_function())`. If it's a top-level entry point, ensure it's run with `asyncio.run(my_async_function())`.
Ensure all tasks managed by `AioPool` are allowed to complete. Using `async with AioPool(...) as pool:` is the recommended way, as it handles proper shutdown. Alternatively, ensure `await pool.join()` is called before the event loop is stopped, or that `pool.map` finishes collecting all results.
Verify that you are passing actual coroutine objects (e.g., the result of calling an `async def` function: `my_coro_func()`, not `my_coro_func`) to methods like `pool.spawn()`, and that any `await` calls are made on valid awaitables.
No dependency data recorded yet.
No resource links recorded.