Skip to main content

aiomultiprocess

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

version documentation changelog license build status code coverage 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 function>, <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.

Running your asynchronous jobs on a pool of worker processes is easy:

from aiohttp import request
from aiomultiprocess import Pool

async def get(url):
    async with request("GET", url) as response:
        return await response.text("utf-8")

async def main():
    urls = ["https://jreese.sh", ...]
    async with Pool() as pool:
        async for result in pool.map(get, urls):
            ...  # process result

Take a look at the User Guide for more details and examples.

For further context, watch the PyCon US 2018 talk about aiomultiprocess, "Thinking Outside the GIL":

IMAGE ALT TEXT

Slides available at Speaker Deck.

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.8.0.tar.gz (15.3 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: aiomultiprocess-0.8.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.0

File hashes

Hashes for aiomultiprocess-0.8.0.tar.gz
Algorithm Hash digest
SHA256 c613ac39973bbf0ceeb2fdb296ca1ebf9e55d2e0f748f50ae3c116a8b05be01a
MD5 dde323d34012b98c3c5b5c8742352522
BLAKE2b-256 194c3e879e97f27ec4f62c53f433d8a35066cd3dc85b5d44b91dd1204ea92875

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 Sentry Error logging StatusPage Status page