ontometer_corpus.supervisor¶
Run one task per OS process, killing any that overrun a wall-clock budget.
Corpus passes that re-read raw ontology files meet pathological inputs: a
malformed RDF/XML file can hold lxml inside C code indefinitely. signal.alarm
fires only between Python bytecodes, so it cannot interrupt such a hang; a
supervisor that terminates the worker from outside can. Each task therefore
gets its own forked process and a one-way pipe for its single result, and the
parent enforces the budget with SIGTERM, then SIGKILL.
The design choice is one process per task rather than a pool: a pool recycles workers, so a task that hangs or leaks memory takes innocent tasks down with it. Forking per task costs milliseconds; the tasks here cost seconds.
Attributes¶
T = TypeVar('T')
module-attribute
¶
Record = dict[str, Any]
module-attribute
¶
Functions:¶
run_supervised(tasks, target, on_error, *, timeout_s, workers=8, progress_every=200, label='done')
¶
Apply target to every task in a separate process; return the records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks
|
Iterable[T]
|
Inputs, each passed to target in its own forked process. |
required |
target
|
Callable[[T], Record]
|
Produces one picklable record per task. |
required |
on_error
|
Callable[[T, str], Record]
|
Builds the record for a task that raised, timed out, or died. |
required |
timeout_s
|
float
|
Wall-clock budget per task, enforced from outside. |
required |
workers
|
int
|
Maximum concurrent processes. |
8
|
progress_every
|
int
|
Print a progress line every N completed tasks. |
200
|
label
|
str
|
Verb for the progress line. |
'done'
|
Returns:
| Type | Description |
|---|---|
list[Record]
|
One record per task, in completion order. |