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.2.0.tar.gz (17.5 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.2.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file livesubprocess-0.2.0.tar.gz.

File metadata

  • Download URL: livesubprocess-0.2.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for livesubprocess-0.2.0.tar.gz
Algorithm Hash digest
SHA256 29b11446f0fe19e0e81831e276d2b9492d0f1ffe4a6a8862f88919dfd4be1396
MD5 93ca317ac8bb35f2c49d64d2bb5f8489
BLAKE2b-256 4a1de9c529a24af43250a9f4cd0cce48c39bf4b28d54c6c65a19d33d219adc0b

See more details on using hashes here.

File details

Details for the file livesubprocess-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: livesubprocess-0.2.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.12

File hashes

Hashes for livesubprocess-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a495e8961cf53d09565970e5da17d9a4bdfb248e010a2f0df6d44ba340b5f935
MD5 d51f25ee1106320b46e405a53cd30f41
BLAKE2b-256 4ee65e6049a96558457d983ca8843786880bbdc3d97752a3c1ee4e3e0eccb39b

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