Skip to main content

aiopipe -- Multiprocess communication pipes for asyncio

Documentation Build status

This package wraps the os.pipe simplex communication pipe so it can be used as part of the non-blocking asyncio event loop. A duplex pipe is also provided, which allows reading and writing on both ends.

Simplex example

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

>>> from multiprocessing import Process
>>> import asyncio
>>>
>>> from aiopipe import aiopipe
>>>
>>> async def main():
...     rx, tx = aiopipe()
...
...     with tx.detach() as tx:
...         proc = Process(target=childproc, args=(tx,))
...         proc.start()
...
...     # The write end is now available in the child process
...     # and detached from the parent process.
...
...     async with rx.open() as rx:
...         msg = await rx.readline()
...
...     proc.join()
...     return msg
>>>
>>> def childproc(tx):
...     asyncio.run(childtask(tx))
>>>
>>> async def childtask(tx):
...     async with tx.open() as tx:
...         tx.write(b"hi from the child process\n")
>>>
>>> asyncio.run(main())
b'hi from the child process\n'
>>>

Duplex example

The following example shows a parent and child process sharing a duplex pipe to exchange messages.

>>> from multiprocessing import Process
>>> import asyncio
>>>
>>> from aiopipe import aioduplex
>>>
>>> async def main():
...     mainpipe, chpipe = aioduplex()
...
...     with chpipe.detach() as chpipe:
...         proc = Process(target=childproc, args=(chpipe,))
...         proc.start()
...
...     # The second pipe is now available in the child process
...     # and detached from the parent process.
...
...     async with mainpipe.open() as (rx, tx):
...         req = await rx.read(5)
...         tx.write(req + b" world\n")
...         msg = await rx.readline()
...
...     proc.join()
...     return msg
>>>
>>> def childproc(pipe):
...     asyncio.run(childtask(pipe))
>>>
>>> async def childtask(pipe):
...     async with pipe.open() as (rx, tx):
...         tx.write(b"hello")
...         rep = await rx.readline()
...         tx.write(rep.upper())
>>>
>>> asyncio.run(main())
b'HELLO WORLD\n'
>>>

Installation

This package requires Python 3.7+ and can be installed with pip:

pip install aiopipe

Release files for aiopipe 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiopipe 0.2.2
File Size Uploaded
aiopipe-0.2.2.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiopipe 0.2.2
File Interpreter ABI Platform
aiopipe-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / aiopipe-0.2.2.tar.gz

Download URL aiopipe-0.2.2.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
666282e6e94b8bbd3a49330cd5d4ac95dc217a0d7c2597fb3f43753893a3154d
BLAKE2b-256 checksum
How to use checksums
acc5ede3669a577fc26add076767f3c99b6736b58984e6b3af06a39e1d7ba41b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release files / aiopipe-0.2.2-py3-none-any.whl

Download URL aiopipe-0.2.2-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4796341a4352167452e436f77696e5596ebf9728eb4e4adbc02c8bb66d3349ed
BLAKE2b-256 checksum
How to use checksums
7e0daaf3fd512ca381c418ce776ea087c1ce4bf37eaf9711a83f336c2e695d97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page