reprospect.utils.subprocess_helpers module
- reprospect.utils.subprocess_helpers.popen_stream(*, args: Sequence[str | Path], **kwargs) Generator[str, None, None]View on GitHub
Yield lines from a
subprocess.Popenlazily, with robust error handling and resource cleanup.- Parameters:
args – Command to run.
kwargs – Additional arguments to pass to
subprocess.Popen.
Launch a subprocess with both stdout and stderr captured as text streams.
Lazily yield each line from stdout as it becomes available.
After stdout is exhausted, wait for the process to finish.
If the process exits with a nonzero return code, raise
subprocess.CalledProcessErrorwith captured stderr.Guarantee resource cleanup:
If the process hasn’t finished, it is terminated.
If termination fails (within 2 seconds), the process is forcibly killed.