tlc.utils.subprocess_with_parent_termination¶

Subprocess management with automatic parent termination.

Module Contents¶

Classes¶

Class

Description

SubprocessWithParentTerminationBase

Create a subprocess that will terminate when the parent process dies.

API¶

class SubprocessWithParentTerminationBase(
process: Popen,
timeout: float | None,
)¶

Create a subprocess that will terminate when the parent process dies.

This is useful for creating subprocesses that should be terminated when the parent process dies even if the parent dies unexpectedly or forcefully.

As a convenience the class also provides a context manager interface that will terminate the subprocess when the context is exited:

```python
with SubprocessWithParentTermination(["ls", "-l"]) as process:
    process.wait()
```
kill() None¶

Kill the subprocess forcefully.

poll() int | None¶

Check if the subprocess is still running.

Returns:

Return code if finished, None if still running.

terminate() None¶

Terminate the subprocess gracefully.

wait(
timeout: float | None = None,
) int¶

Wait for the subprocess to complete.

Parameters:

timeout – Timeout in seconds, or None for no timeout.

Returns:

Return code of the subprocess.