Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

live-tee-and-capture

Run a command and tee its stdout/stderr in real time to your terminal while also capturing them.

  • Outputs are relayed in real time with no artificial buffering (a dedicated thread drains each pipe as data arrives) - ideal for real-time logs and progress bars.
  • You can enable/disable teeing stdout/stderr independently.
  • Optional timeout: the command's direct process is killed and TimeoutExpired is raised if it does not exit in time.
  • File descriptors and reader threads are always cleaned up, even if launching fails or the command times out.
  • Descendant processes are not killed automatically; inherited output pipes cannot delay completion after the direct process exits.

Usage

Example

from live_tee_and_capture import live_tee_and_capture

exit_code, stdout_bytes, stderr_bytes = live_tee_and_capture(
    ['ls', '-la'],
    tee_stdout=True,
    tee_stderr=True,
)

print('Exit code:', exit_code)
print('Captured stdout:', stdout_bytes.decode())
print('Captured stderr:', stderr_bytes.decode())

Function Signature

def live_tee_and_capture(
    command: Sequence[Text],
    tee_stdout: bool = True,
    tee_stderr: bool = True,
    timeout: Optional[float] = None,
) -> Tuple[int, bytearray, bytearray]:
    ...

If timeout (in seconds) is given and the command does not exit within that time, its direct process is killed and a TimeoutExpired exception is raised. Descendant processes are not terminated automatically:

from live_tee_and_capture import live_tee_and_capture, TimeoutExpired

try:
    live_tee_and_capture(['sleep', '30'], timeout=5)
except TimeoutExpired as e:
    print('Timed out:', e.command, e.timeout)
    # Output captured before the command was killed:
    print('Partial stdout:', e.stdout.decode())
    print('Partial stderr:', e.stderr.decode())

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

Release files for live-tee-and-capture 0.1.0a1

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

Source distribution (sdist)

Source distribution for live-tee-and-capture 0.1.0a1
File Size Uploaded
live_tee_and_capture-0.1.0a1.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for live-tee-and-capture 0.1.0a1
File Interpreter ABI Platform
live_tee_and_capture-0.1.0a1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 15.9 kB

Release files / live_tee_and_capture-0.1.0a1.tar.gz

Download URL live_tee_and_capture-0.1.0a1.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
542dd23e0ae3baeb7a97a5b72bb5c316d8ab4f5735fb8c6927e2bf1ec2e24fe1
BLAKE2b-256 checksum
How to use checksums
49b32fcc8f5f6cb8acf6c28788755337a8ae95ec771ac29af08aa52892d4f753
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / live_tee_and_capture-0.1.0a1-py2.py3-none-any.whl

Download URL live_tee_and_capture-0.1.0a1-py2.py3-none-any.whl
Size 6.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
60ea18541c9207d6de16e18949b020852c80cdd7163b9ff1fb95f01790d02ca2
BLAKE2b-256 checksum
How to use checksums
8322fe1a1ff6e0cae83c38a574590dfa789eaec8f3bda97c9cbb5574d4496d6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.0a1 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