Streaming
provide.foundation.process.aio.streaming
¶
TODO: Add module docstring.
Classes¶
Functions¶
async_stream
async
¶
async_stream(
cmd: list[str],
cwd: str | Path | None = None,
env: Mapping[str, str] | None = None,
timeout: float | None = None,
stream_stderr: bool = False,
**kwargs: Any
) -> AsyncIterator[str]
Stream command output line by line asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command and arguments as a list |
required |
cwd
|
str | Path | None
|
Working directory for the command |
None
|
env
|
Mapping[str, str] | None
|
Environment variables |
None
|
timeout
|
float | None
|
Command timeout in seconds |
None
|
stream_stderr
|
bool
|
Whether to merge stderr into stdout |
False
|
**kwargs
|
Any
|
Additional subprocess arguments |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[str]
|
Lines of output from the command |
Raises:
| Type | Description |
|---|---|
ProcessError
|
If command fails |
ProcessTimeoutError
|
If timeout is exceeded |
Source code in provide/foundation/process/aio/streaming.py
check_stream_exit_code
¶
Check if process exited successfully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
Any
|
Subprocess to check |
required |
cmd_str
|
str
|
Command string for error messages |
required |
Raises:
| Type | Description |
|---|---|
ProcessError
|
If process exited with non-zero code |
Source code in provide/foundation/process/aio/streaming.py
cleanup_stream_process
async
¶
Clean up subprocess resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
Any
|
Subprocess to clean up |
required |
Source code in provide/foundation/process/aio/streaming.py
create_stream_subprocess
async
¶
create_stream_subprocess(
cmd: list[str],
cwd: str | None,
run_env: dict[str, str],
stream_stderr: bool,
kwargs: dict[str, Any],
) -> Any
Create subprocess for streaming.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command to execute as list |
required |
cwd
|
str | None
|
Working directory |
required |
run_env
|
dict[str, str]
|
Environment variables |
required |
stream_stderr
|
bool
|
Whether to stream stderr to stdout |
required |
kwargs
|
dict[str, Any]
|
Additional subprocess parameters |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Created subprocess |
Source code in provide/foundation/process/aio/streaming.py
read_lines_with_timeout
async
¶
Read lines from process stdout with timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
Any
|
Subprocess to read from |
required |
timeout
|
float
|
Timeout in seconds |
required |
cmd_str
|
str
|
Command string for error messages |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of output lines |
Raises:
| Type | Description |
|---|---|
ProcessTimeoutError
|
If timeout exceeded |