Displays the stdout and stderr of the subprocess in real time.
Project description
Live Subprocess
Displays the stdout and stderr of the subprocess in real time.
Advantage
- Displays subprocess stdout and stderr in real time as the process runs — not buffered until exit.
- Uses a PTY (pseudo-terminal) on POSIX so the child process keeps line-buffering active, just as it would in a real terminal.
- Cross-platform: PTY-based on POSIX, thread-backed pipe reader on Windows.
- Zero runtime dependencies.
- Async/await native; captures and returns the full output string for programmatic use.
Quickstart
Install:
pip install livesubprocess
Run a command with real-time output (POSIX):
import asyncio
from livesubprocess import LiveSubProcessFactory
async def main() -> None:
pty = LiveSubProcessFactory.create_pty()
stdout, returncode = await pty.run(["python", "-u", "script.py"])
asyncio.run(main())
Run a command with real-time output (POSIX and Windows):
import asyncio
import subprocess
from livesubprocess import LiveSubProcessFactory
async def main() -> None:
proc = subprocess.Popen(
["python", "-u", "script.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
live = LiveSubProcessFactory.create_popen(proc)
stdout, returncode = await live.wait()
asyncio.run(main())
PTY vs. Popen
PTY (create_pty) |
Popen (create_popen) |
|
|---|---|---|
| Platforms | POSIX only | POSIX and Windows |
| Process creation | Managed by livesubprocess |
You create the Popen object |
| Line-buffering | Yes — child sees a real TTY | Depends on the child process |
| Use when | Simplest API on POSIX | Windows support needed, or you need to configure Popen directly (env, cwd, shell, etc.) |
Both run() and wait() return (stdout_and_stderr: str, returncode: int).
How do I...
-
Wrap an existing
subprocess.Popen? UseLiveSubProcessFactory.create_popen(). This works on both POSIX and Windows.import asyncio import subprocess from livesubprocess import LiveSubProcessFactory async def main() -> None: proc = subprocess.Popen( ["ffmpeg", "-i", "input.mp4", "output.mp4"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) live = LiveSubProcessFactory.create_popen(proc) stdout, returncode = await live.wait() asyncio.run(main())
-
Stop the reader early (before terminating the process)? Call
live.stop()beforepopen.terminate()orpopen.communicate()to deregister the fd readers cleanly.
Credits
This package was created with Cookiecutter and the yukihiko-shinoda/cookiecutter-pypackage project template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file livesubprocess-0.1.0.tar.gz.
File metadata
- Download URL: livesubprocess-0.1.0.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09748c256567aa509b3c3ad075429e0ef48c9aea02eb3dc0eaf33f82db1dfab1
|
|
| MD5 |
286d60403246b6f6aa4eab6bbd27eb26
|
|
| BLAKE2b-256 |
fb8f47bb50b84c1dc123ef91fae0b0321180e726ef9707696c11e739c5cc2f97
|
File details
Details for the file livesubprocess-0.1.0-py3-none-any.whl.
File metadata
- Download URL: livesubprocess-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff65c0621ada4f8554710d096347cd33c8fe29f8c0dfa9d3536155f6bfd243be
|
|
| MD5 |
6a4e328a44e21ccd0cf3ff68d109060a
|
|
| BLAKE2b-256 |
7df3c30df64a7686d178654df8a57ea2f13b95d23b2083c09adffe92708e5d69
|