Skip to main content
Usage Release Development
MIT License PyPI version Build status
Python versions Tag Maintainability
pip install aiosubprocess This project uses calendar-based versioning scheme Test Coverage
Downloads This project uses the "black" style formatter for Python code

aiosubprocess

A zero-dependency async subprocess that keeps on getting stdout and stderr.

How to use

Example 1: Hello World

A classic Hello World. It prints Hello World! in the shell and redirects the stdout to print().

import asyncio
from aiosubprocess import Process

asyncio.get_event_loop().run_until_complete(
    Process("echo Hello World!", stdout=print).shell()
)
$> python ex1_minimal.py
[AIO Subprocess-0] Hello World!

Process finished with exit code 0

Example 2: Two Processes

One process writes to a file, and a second process logs the content of the file in real time.

import asyncio
from aiosubprocess import Process

loop = asyncio.get_event_loop()
reader = Process(
    """for i in {1..5}
    do
       echo "Hello $i World" > tempfile.log
       sleep 1
    done""",
    loop=loop,
    name="Writer",
)
writer = Process(
    "timeout --foreground 10s tail -f tempfile.log",
    loop=loop,
    name="Reader",
    expected_returncode=124,  # Because timeout is expected
)
awaitable_reader = reader.shell()
awaitable_writer = writer.shell()
gathered = asyncio.gather(awaitable_reader, awaitable_writer, loop=loop)
asyncio.get_event_loop().run_until_complete(gathered)
assert gathered.result() == [True, True]

Which does exactly this:

Example animation

Why?

There are many scenario where we need to keep an eye on a subprocess output. If we want to do so in realtime (and redirect it to logs or a GUI), the boilerplate is tedious.

The other solution is to wait for the subprocess to exit and read the stdout/stderr afterwards.

This library implements this boilerplate, so you don't have to.

Release files for aiosubprocess 2021.5.3

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

Source distribution (sdist)

Source distribution for aiosubprocess 2021.5.3
File Size Uploaded
aiosubprocess-2021.5.3.tar.gz 924.2 kB Details

Built distribution (wheel)

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

Total release size: 929.3 kB

Release files / aiosubprocess-2021.5.3.tar.gz

Download URL aiosubprocess-2021.5.3.tar.gz
Size 924.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9a59a717efe7853d33dd10d31339842d2c9c0ab28bfd1104f3324fd486a95373
BLAKE2b-256 checksum
How to use checksums
63febe124f33501c47cf7438f8141d1497c056b86a8a5142da7677a6c65f18df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release files / aiosubprocess-2021.5.3-py3-none-any.whl

Download URL aiosubprocess-2021.5.3-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7e314e539374c7b4fc44a16e4bcffc53cf7a3b59996e748db47133aff0f31a0
BLAKE2b-256 checksum
How to use checksums
54720bc7364b6b50b718634afebacad545c49a4b8bd59fab404b3702cfe48140
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release history Release notifications | RSS feed

This release

2021.5.3 This release

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