Skip to main content

aio-pool

Extending Python's multiporcessing.Pool to support coroutine functions.
Can be useful for when using a server with very high bandwidth or doing both very large IO and CPU tasks at the same time.

All methods of multiprocessing.Pool are supported.
All paramters for multiprocessing.Pool are supported.

examples:

Setting concurrency limit. This means each process can run with up to 8 concurrent tasks at a time.

import asyncio
from aio_pool import AioPool


async def powlong(a):
  await asyncio.sleep(1)
  return a**2

if __name__ == '__main__':
  with AioPool(processes=2, concurrency_limit=8) as pool:
    results = pool.map(powlong, [i for i in range(16)])  # Should take 2 seconds (2*8).
    print(results) 

Async initliazers are also suppported.

import asyncio
from aio_pool import AioPool

async def start(message):
  await asyncio.sleep(1)
  print(message)

async def powlong(a):
  await asyncio.sleep(1)
  return a**2

if __name__ == '__main__':
  with AioPool(processes=2, 
               concurrency_limit=8, 
               initializer=start,
               init_args=("Started with AioPool", )) as pool:
    results = pool.map(powlong, [i for i in range(16)])  # Should take 2 seconds (2*8).
    print(results) 
    

By default, AioPool also set up a default executor for any non-async tasks.
The size can be determined by threadpool_size arguemnt, which defaults to 1.
None default event loops(uvloop for example) are supported as well, using the loop_initializer argument.
Also, non-async functions are supported by default, as the AioPool worker identify if the function is async or not.
If the function is not async, it runs inside the threadpool, to allow the requested concurrency.
This means that order of execution is not guaranteed, even if the function is not async.
However, the order of results is guaranteed through the pool API (map, starmap, apply, etc...).

from aio_pool import AioPool
import uvloop

with AioPool(loop_initializer=uvloop.new_event_loop, threadpool_size=4) pool:
  pool.map(print, [i for i in range(8)])

Metadata

Release files for aio-pool 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aio-pool 0.2.0
File Size Uploaded Provenance Actions
aio-pool-0.2.0.tar.gz 5.7 kB Without provenance Details for aio-pool-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aio-pool 0.2.0
File Interpreter ABI Platform Actions
aio_pool-0.2.0-py3-none-any.whl Python 3 none any Details for aio_pool-0.2.0-py3-none-any.whl

Total release size: 11.6 kB

Release files / aio-pool-0.2.0.tar.gz

Download URL aio-pool-0.2.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
37c4155e5c6e03c8a7c45c84a34cca47f9214c48f1637ecbc7b39a33716ec463
BLAKE2b-256 checksum
How to use checksums
95c324b23a97d666f44bf53b224b19e798673a2c048265cfe30fc5219fbd7ac2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.9.6 Linux/5.8.0-1036-azure

Release files / aio_pool-0.2.0-py3-none-any.whl

Download URL aio_pool-0.2.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0b609cd83da06312fe50f5e2f75803029be494c9b237e68fe59d585c704e839
BLAKE2b-256 checksum
How to use checksums
77108b3e8c8a7c7d3aff1145ebf4c441e3ed29d49d8d4dddb106c0dcf807af64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.9.6 Linux/5.8.0-1036-azure

Security for aio-pool 0.2.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page