httk.workflow.supervision¶
Structured, argv-only process supervision for native runners.
Every event is dispatched to the in-process monitors and to the executable checkers under one supervisor-wide lock, so a monitor is never entered concurrently with itself or with another monitor, and a checker never receives an interleaved line on its stdin. A monitor therefore does not have to be thread-safe, but it must return quickly: it delays the whole event stream.
Attributes¶
Seconds between the |
|
Seconds between polls of a followed file that produced no new data. |
|
Bytes of a stream retained in the report when no output path is given. |
|
Bytes of a stream retained in the report when an output path is given. |
|
Diagnostics retained in one report before the middle is dropped. |
Classes¶
Describe one event delivered to a checker. |
|
Describe a structured observation made while supervising a program. |
|
Describe a file to follow while the child process is running. |
|
Describe a versioned executable checker. |
|
The complete result of one supervised command. |
|
Run one command, stream its output, and terminate its process group safely. |
Module Contents¶
- httk.workflow.supervision.DEFAULT_TICK_INTERVAL = 1.0[source]¶
Seconds between the
tickevents delivered to monitors and checkers.
- httk.workflow.supervision.DEFAULT_FOLLOW_INTERVAL = 0.25[source]¶
Seconds between polls of a followed file that produced no new data.
- httk.workflow.supervision.DEFAULT_CAPTURE_LIMIT = 4194304[source]¶
Bytes of a stream retained in the report when no output path is given.
- httk.workflow.supervision.DEFAULT_TAIL_LIMIT = 65536[source]¶
Bytes of a stream retained in the report when an output path is given.
- httk.workflow.supervision.DEFAULT_DIAGNOSTIC_LIMIT = 512[source]¶
Diagnostics retained in one report before the middle is dropped.
- class httk.workflow.supervision.SourceEvent[source]¶
Describe one event delivered to a checker.
- Parameters:
event – Identify the event kind.
source – Identify the stream or process that produced it.
line – Preserve the event line when one exists.
timestamp – Preserve the event timestamp, or generate one when absent.
- class httk.workflow.supervision.Diagnostic[source]¶
Describe a structured observation made while supervising a program.
- Parameters:
code – Name the stable diagnostic code.
severity – Classify the diagnostic severity.
summary – Summarize the observation.
source – Identify the source that produced it.
evidence – Preserve supporting evidence when present.
stop – Request termination of the supervised command.
- class httk.workflow.supervision.FollowSource[source]¶
Describe a file to follow while the child process is running.
- Parameters:
path – Locate the file to follow.
name – Identify the source in emitted events.
inactivity_timeout – Stop when no data arrives for this interval.
- path: pathlib.Path[source]¶
- class httk.workflow.supervision.CheckerSpec[source]¶
Describe a versioned executable checker.
- Parameters:
argv – Supply the checker command and arguments.
required – Require the checker to remain available for the run.
sources – Select files the checker follows.
- sources: tuple[FollowSource, Ellipsis] = ()[source]¶
- classmethod from_mapping(value)[source]¶
Validate and build a checker specification from a mapping.
- Parameters:
value (collections.abc.Mapping[str, object]) – Supply the serialized checker specification.
- Returns:
The validated checker specification.
- Raises:
ValueError – If the mapping has an invalid checker format or source.
- Return type:
- class httk.workflow.supervision.ProcessReport[source]¶
The complete result of one supervised command.
stdoutandstderrare bounded: when an output path was given they hold at most the run’s tail limit and the file named bystdout_pathorstderr_pathis authoritative; otherwise they hold at most the run’s capture limit.stdout_bytesandstderr_bytesalways count every byte the program produced, andstdout_truncatedandstderr_truncatedsay whether anything was dropped from the retained tail.- Parameters:
argv – Preserve the executed command.
started_at – Record when execution began.
finished_at – Record when execution ended.
returncode – Record the process return code.
termination – Record why execution ended.
stdout – Preserve the captured stdout tail.
stderr – Preserve the captured stderr tail.
diagnostics – Preserve emitted diagnostics.
stdout_path – Locate the authoritative stdout file when configured.
stderr_path – Locate the authoritative stderr file when configured.
stdout_bytes – Count all stdout bytes produced.
stderr_bytes – Count all stderr bytes produced.
stdout_truncated – Indicate that stdout was truncated.
stderr_truncated – Indicate that stderr was truncated.
dropped_diagnostics – Count diagnostics dropped from the middle.
- diagnostics: tuple[Diagnostic, Ellipsis][source]¶
- property timed_out: bool[source]¶
Report whether the process ended because of a timeout.
- Returns:
Whether the termination reason starts with
timeout.- Return type:
- write(path)[source]¶
Write the serialized report atomically.
- Parameters:
path (str | os.PathLike[str]) – Locate the report file to write.
- Returns:
The report path.
- Return type:
- class httk.workflow.supervision.ProcessSupervisor(*, monitors=(), checkers=(), follow=())[source]¶
Run one command, stream its output, and terminate its process group safely.
Monitors and checkers observe the same event stream under one lock, so an in-process monitor does not have to be thread-safe. Whatever happens during a run - including an exception raised by the caller’s monitor - the signal handlers are restored, the child’s process group is terminated and reaped, the reader threads are joined, and the output handles are closed before
run()returns or propagates.- Parameters:
monitors (collections.abc.Sequence[EventMonitor]) – Supply in-process event monitors.
checkers (collections.abc.Sequence[CheckerSpec]) – Supply executable checker specifications.
follow (collections.abc.Sequence[FollowSource]) – Supply files to follow during the run.
- run(argv, *, timeout=None, cwd=None, environment=None, termination_grace=10.0, stdout_path=None, stderr_path=None, tick_interval=DEFAULT_TICK_INTERVAL, follow_interval=DEFAULT_FOLLOW_INTERVAL, capture_limit=DEFAULT_CAPTURE_LIMIT, tail_limit=DEFAULT_TAIL_LIMIT, diagnostic_limit=DEFAULT_DIAGNOSTIC_LIMIT)[source]¶
Run one command to completion and return its structured report.
- Parameters:
argv (collections.abc.Sequence[str]) – Supply the command and arguments.
timeout (float | None) – Stop the command after this interval.
cwd (str | os.PathLike[str] | None) – Select the command working directory.
environment (collections.abc.Mapping[str, str] | None) – Supply the command environment.
termination_grace (float) – Wait this long after requesting termination.
stdout_path (str | os.PathLike[str] | None) – Write stdout to this authoritative file.
stderr_path (str | os.PathLike[str] | None) – Write stderr to this authoritative file.
tick_interval (float) – Set the interval between tick events.
follow_interval (float) – Set the interval between followed-file polls.
capture_limit (int) – Bound retained output without an output file.
tail_limit (int) – Bound retained output with an output file.
diagnostic_limit (int) – Bound retained diagnostics.
- Returns:
The structured process report.
- Raises:
ValueError – If command or supervision limits are invalid.
- Return type: