Skip to main content

Displays the stdout and stderr of the subprocess in real time.

Project description

Live Subprocess

Test CodeQL Code Coverage Maintainability Dependabot Python versions PyPI - Downloads X URL

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? Use LiveSubProcessFactory.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() before popen.terminate() or popen.communicate() to deregister the fd readers cleanly.

Credits

This package was created with Cookiecutter and the yukihiko-shinoda/cookiecutter-pypackage project template.

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

livesubprocess-0.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

livesubprocess-0.1.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

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

Hashes for livesubprocess-0.1.0.tar.gz
Algorithm Hash digest
SHA256 09748c256567aa509b3c3ad075429e0ef48c9aea02eb3dc0eaf33f82db1dfab1
MD5 286d60403246b6f6aa4eab6bbd27eb26
BLAKE2b-256 fb8f47bb50b84c1dc123ef91fae0b0321180e726ef9707696c11e739c5cc2f97

See more details on using hashes here.

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

Hashes for livesubprocess-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff65c0621ada4f8554710d096347cd33c8fe29f8c0dfa9d3536155f6bfd243be
MD5 6a4e328a44e21ccd0cf3ff68d109060a
BLAKE2b-256 7df3c30df64a7686d178654df8a57ea2f13b95d23b2083c09adffe92708e5d69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page