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.

Files for aiopipe, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size aiopipe-0.1.2-py3-none-any.whl (3.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aiopipe-0.1.2.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page