subprocess-multitee

raw JSON →
0.2.1 verified Sat May 09 auth: no python

Provides a `multitee` function that splits stdout/stderr from subprocesses into multiple sinks (e.g., files, pipes, callables), along with a `Popen` wrapper. Currently at v0.2.1, requires Python >= 3.6. Low release cadence; last release Nov 2023.

pip install subprocess-multitee
error ImportError: cannot import name 'multitee' from 'subprocess_multitee'
cause Trying to import from a stale cached installation or incorrect path.
fix
Reinstall: pip install --upgrade subprocess-multitee and import as from subprocess_multitee import multitee.
error AttributeError: module 'subprocess_multitee' has no attribute 'Popen'
cause Installed version is very old (<0.1.0?). Popen was added later.
fix
Upgrade to latest: pip install --upgrade subprocess-multitee.
gotcha The `multitee` function expects writable objects that accept lines (e.g., file objects opened with 'w' and callables that take a string). Do not pass binary streams unless you set `text=True` in Popen.
fix Ensure sinks accept string lines when using text mode, or use bytes mode consistently.
breaking A bug in v0.1.1 and earlier could stall subprocess writes when reading single bytes. v0.2.0 resolved this by using an internal queue.
fix Upgrade to >=0.2.0.
gotcha The `Popen` wrapper does not mirror the full `subprocess.Popen` interface. Arguments like `bufsize`, `pipesize`, or `pass_fds` may not be supported.
fix Check the docs for supported parameters; fall back to raw `subprocess.Popen` if you need unsupported features.

Basic usage: split subprocess output into multiple sinks (callables, file objects, etc.) using the Popen wrapper.

from subprocess_multitee import multitee, Popen

# Capture stdout and stderr to both a list and a file
out = []
err = []
proc = Popen(
    ['echo', 'hello'],
    stdout=multitee(lambda line: out.append(line), open('/tmp/stdout.log', 'w')),
    stderr=multitee(lambda line: err.append(line), open('/tmp/stderr.log', 'w')),
    text=True
)
proc.wait()