Finally, a subprocess type that streams out stdout/stderr easily
Capturing the stderr AND stdout from a process in python is not that easy. This class makes this capturing much easier by delegating the line capturing to seperate threads. This capture can be totally in memory or can optionally be streamed to a output stream such as a file handle.
This class will unconditionally launch a shell command and the input will always be string, not an array like what is accepted by subprocess.Popen().
Example:
Super simple example:
from capturing_process import CapturingProcess
out_stream = StringIO()
p = CapturingProcess("echo hi", stdout=out_stream)
p.wait()
self.assertIn("hi", out_stream.getvalue())
self.assertIn("hi", p.get_stdout())
For splitting the output to stdout and a file you'd write a stream class like so:
import logging
class MyStream:
def __init__(self) -> None:
pass
def write(self, data: str) -> None:
logging.info(data.rstrip('\n'))
print(data, end="")
out_stream = MyStream()
proc = CapturingProcess("echo hi", stdout=out_stream)
proc.wait() # Output will be captured in logging file and stdout
To silence an output stream (stdout/stderr) drop a StringIO object as an argument to the CapturingProcess like so:
If you want the entire stdout/stderr bytes
proc.get_stdout()
proc.get_stderr()
Python version: 3.6+
Because of the use of type annotations, this library is not compatible with python 2.7 However you are free to strip out these type annotations and this project should work pretty well.
Links:
Versions
- 1.0.9: stdout/stderr threads are now forcefully killed within .1 second if they don't join.
- 1.0.8: Fixes CapturingProcess.kill blocking if the stdout and stderr threads fail to join.
Metadata
Release files for capturing-process 1.0.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| capturing_process-1.0.13.tar.gz | 6.5 kB | Without provenance | Details for capturing_process-1.0.13.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| capturing_process-1.0.13-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for capturing_process-1.0.13-py2.py3-none-any.whl |
Total release size: 13.1 kB
Release files / capturing_process-1.0.13.tar.gz
| Download URL | capturing_process-1.0.13.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4eb6d2806d68826f62ce509c0253ba46845418c2b75f562e43da37f3d1306a5b
|
|
BLAKE2b-256 checksum How to use checksums |
680cee2ddde6d9e4de7752ce899ee7d9aa836834161086ce47fefb793603a341
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.10
|
Release files / capturing_process-1.0.13-py2.py3-none-any.whl
| Download URL | capturing_process-1.0.13-py2.py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b2b02c17aad6b304bea31673420db254a9154c9ecf07fcfb1829221cd8fb3eae
|
|
BLAKE2b-256 checksum How to use checksums |
b264a41cde56f82360249b3e71950e7a1a96a76b73e96f77c54f4d4fd24f6682
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.10
|
Security for capturing-process 1.0.13
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.