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 |
Source code in provide/foundation/process/lifecycle/monitoring.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |