MCPcopy
hub / github.com/omnilib/aiomultiprocess

github.com/omnilib/aiomultiprocess @v0.9.1 sqlite

repository ↗ · DeepWiki ↗ · release v0.9.1 ↗
121 symbols 449 edges 14 files 50 documented · 41%
README

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://noswap.com", ...]
    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 Amethyst 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.

Core symbols most depended-on inside this repo

start
called by 16
aiomultiprocess/core.py
is_alive
called by 13
aiomultiprocess/core.py
join
called by 10
aiomultiprocess/core.py
get_context
called by 8
aiomultiprocess/core.py
apply
called by 5
aiomultiprocess/pool.py
map
called by 5
aiomultiprocess/pool.py
starmap
called by 4
aiomultiprocess/pool.py
join
called by 4
aiomultiprocess/pool.py

Shape

Method 87
Function 19
Class 14
Route 1

Languages

Python100%

Modules by API surface

aiomultiprocess/pool.py25 symbols
aiomultiprocess/core.py24 symbols
aiomultiprocess/tests/core.py22 symbols
aiomultiprocess/tests/pool.py14 symbols
aiomultiprocess/tests/base.py12 symbols
aiomultiprocess/scheduler.py11 symbols
aiomultiprocess/tests/perf.py8 symbols
aiomultiprocess/tests/scheduler.py3 symbols
aiomultiprocess/types.py2 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add aiomultiprocess \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact