Index
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
provide.foundation.process.lifecycle
¶
Classes¶
ManagedProcess
¶
ManagedProcess(
command: list[str],
*,
cwd: str | Path | None = None,
env: Mapping[str, str] | None = None,
capture_output: bool = True,
text_mode: bool = False,
bufsize: int = 0,
stderr_relay: bool = True,
**kwargs: Any,
)
A managed subprocess with lifecycle support, monitoring, and graceful shutdown.
This class wraps subprocess.Popen with additional functionality for: - Environment management - Output streaming and monitoring - Health checks and process monitoring - Graceful shutdown with timeouts - Background stderr relaying
Initialize a ManagedProcess.
Source code in provide/foundation/process/lifecycle/managed.py
Attributes¶
Functions¶
__enter__
¶
__exit__
¶
cleanup
¶
Clean up process resources.
Source code in provide/foundation/process/lifecycle/managed.py
is_running
¶
launch
¶
Launch the managed process.
Raises:
| Type | Description |
|---|---|
ProcessError
|
If the process fails to launch |
StateError
|
If the process is already started |
Source code in provide/foundation/process/lifecycle/managed.py
read_char_async
async
¶
Read a single character from stdout asynchronously.
Source code in provide/foundation/process/lifecycle/managed.py
read_line_async
async
¶
Read a line from stdout asynchronously with timeout.
Source code in provide/foundation/process/lifecycle/managed.py
terminate_gracefully
¶
Terminate the process gracefully with a timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Maximum time to wait for graceful termination |
DEFAULT_PROCESS_TERMINATE_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
bool
|
True if process terminated gracefully, False if force-killed |
Source code in provide/foundation/process/lifecycle/managed.py
Functions¶
wait_for_process_output
async
¶
wait_for_process_output(
process: ManagedProcess,
expected_parts: list[str],
timeout: float = DEFAULT_PROCESS_WAIT_TIMEOUT,
buffer_size: int = 1024,
) -> str
Wait for specific output pattern from a managed process.
This utility reads from a process stdout until a specific pattern (e.g., handshake string with multiple pipe separators) appears.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
ManagedProcess
|
The managed process to read from |
required |
expected_parts
|
list[str]
|
List of expected parts/separators in the output |
required |
timeout
|
float
|
Maximum time to wait for the pattern |
DEFAULT_PROCESS_WAIT_TIMEOUT
|
buffer_size
|
int
|
Size of read buffer |
1024
|
Returns:
| Type | Description |
|---|---|
str
|
The complete output buffer containing the expected pattern |
Raises:
| Type | Description |
|---|---|
ProcessError
|
If process exits unexpectedly |
TimeoutError
|
If pattern is not found within timeout |