Skip to main content

aiomultiprocess

Take a modern Python codebase to the next level of performance.

build status version license code style

On their own, AsyncIO and multiprocessing are useful, but limited: AsyncIO still can't exceed the speed of GIL, and multiprocessing only works on one task at a time. But together, they can fully realize their true potential.

aiomultiprocess presents a simple interface, while running a full AsyncIO event loop on each child process, enabling levels of concurrency never before seen in a Python application. Each child process can execute multiple coroutines at once, limited only by the workload and number of cores available.

Gathering tens of thousands of network requests in seconds is as easy as:

async with Pool() as pool:
    results = await pool.map(<coroutine>, <items>)

Install

aiomultiprocess requires Python 3.6 or newer. You can install it from PyPI:

$ pip3 install aiomultiprocess

Usage

Most of aiomultiprocess mimics the standard multiprocessing module whenever possible, while accounting for places that benefit from async functionality.

Executing a coroutine on a child process is as simple as:

from aiomultiprocess import Process

async def foo(...):
    ...

p = Process(target=foo, args=..., kwargs=...)
p.start()
await p.join()

If you want to get results back from that coroutine, then use Worker instead:

from aiomultiprocess import Worker

async def foo(...):
    ...

p = Worker(target=foo, args=..., kwargs=...)
p.start()
await p.join()

print(p.result)

If you want a managed pool of worker processes, then use Pool:

from aiomultiprocess import Pool

async def foo(value):
    return value * 2

async with Pool() as pool:
    result = await pool.map(foo, range(10))

License

aiomultiprocess is copyright John Reese, and licensed under the MIT license. I am providing code in this repository to you under an open source license. This is my personal repository; the license you receive to my code is from me and not from my employer. See the LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiomultiprocess-0.3.0.tar.gz (6.5 kB view details)

Uploaded Source

File details

Details for the file aiomultiprocess-0.3.0.tar.gz.

File metadata

File hashes

Hashes for aiomultiprocess-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0e4529022ec73613408f4b05e4f92d82e990fcc4fbf794bb64a47d0651110c60
MD5 6b7ae3b0817c145e34a6b45386e43f4d
BLAKE2b-256 78e502224329f484a911055bc6ccc9ff5abee355a83121c5a25ad34b6f6df552

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