Skip to main content

AsyncIO version of the standard multiprocessing module

Project description

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:

import asyncio
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
            
if __name__ == '__main__':
    # Python 3.7
    asyncio.run(main())
    
    # Python 3.6
    # loop = asyncio.get_event_loop()
    # loop.run_until_complete(main())

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.

Project 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.9.0.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

aiomultiprocess-0.9.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiomultiprocess-0.9.0.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for aiomultiprocess-0.9.0.tar.gz
Algorithm Hash digest
SHA256 07e7d5657697678d9d2825d4732dfd7655139762dee665167380797c02c68848
MD5 d37e659e06d99450191930fd58908175
BLAKE2b-256 593064e01ec7ecb4aa1123b54401ffc36c16bb1d7155b924f7430a651fb956c1

See more details on using hashes here.

File details

Details for the file aiomultiprocess-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aiomultiprocess-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3036c4c881cfbc63674686e036097f22309017c6bf96b04722a542ac9cac7423
MD5 448130e22dc043f74a35a77ece4b9c04
BLAKE2b-256 e6fabfbf06b737de39a0585c169b132a0cbd735b4db23b4bcfd5daa52b0c7562

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page