Skip to main content

Multiprocess communication pipe for asyncio

Project description

aiopipe -- Multiprocess communication pipe for asyncio

Documentation

This package wraps the os.pipe simplex communication pipe so it can be used as part of the non-blocking asyncio event loop.

Example

The following example opens a pipe with the write end in the child process and the read end in the parent process:

from contextlib import closing
from multiprocessing import Process
import asyncio

from aiopipe import aiopipe

async def mainTask(eventLoop):
    rx, tx = aiopipe()

    with tx.send() as tx:
        proc = Process(target=childProc, args=(tx,))
        proc.start()

    # The write end is now available in the child process
    # and invalidated in the parent process.

    stream = await rx.open(eventLoop)
    msg = await stream.readline()

    assert msg == b"hi from child process\n"

    proc.join()

def childProc(tx):
    eventLoop = asyncio.new_event_loop()
    stream = eventLoop.run_until_complete(tx.open(eventLoop))

    with closing(stream):
        stream.write(b"hi from child process\n")

eventLoop = asyncio.get_event_loop()
eventLoop.run_until_complete(mainTask(eventLoop))

Installation

This package requires Python >= 3.5.0 and can be installed with pip:

pip install aiopipe

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

aiopipe-0.1.3.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

aiopipe-0.1.3-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

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