supervisor
Keeping the compute's children running.
The Supervisor sits above the children and drives them only through their
public methods: it starts and stops them when the compute asks, notices them
dying or hanging, and restarts those that have a RestartPolicy. The children
themselves know nothing of this.
Classes
Supervisor
class Supervisor(children: Mapping[ChildProcess, RestartPolicy | None]):Starts, stops, watches and restarts the compute's children.
Not thread-safe: Compute calls start, stop and watch with its
lock held, and check_health without, as a probe can be slow. Times are
time.monotonic() values passed in, so nothing here waits for a restart.
Arguments
children: Each child, and how to restart it, orNoneto leave it down when it dies and only report it.
Variables
last_pass_at : float | None- Whenwatchlast finished a pass, orNoneif it has not yet.
Methods
check_health
def check_health(self) ‑> None:Health-check every running child.
Never raises: one child's check failing still leaves the rest checked.
reset_pass_clock
def reset_pass_clock(self, now: float) ‑> None:Start the pass clock at now, for a supervisor thread about to run.
Called as the thread starts, so that a thread that has not finished its first pass yet does not read as one that has stopped passing. A compute started a second time gets a new thread, and with it a clock that owes nothing to the thread that went before.
Arguments
now: The current time.
restart_pending
def restart_pending(self, child: ChildProcess) ‑> bool:Whether child is down and waiting to be restarted.
Only an exit already noticed by watch can be pending.
Arguments
child: The child.
restarts
def restarts(self, child: ChildProcess) ‑> int:How many times child has been restarted since it was last started.
Arguments
child: The child.
start
def start(self, child: ChildProcess, now: float) ‑> None:Start child deliberately: it is to be kept running from now on.
Any restart backoff is forgotten. A child already running is left as it is: the same process carries on, so its backoff, restart count and whether it has been ready all stand.
Arguments
child: The child to start.now: The current time.
Raises
Exception: Whatever starting it raised. It is then down, so a child with a restart policy is retried.
stop
def stop(self, child: ChildProcess) ‑> None:Stop child deliberately: it is not to be restarted.
Arguments
child: The child to stop.
watch
def watch(self, now: float) ‑> None:Notice children dying or hanging, and restart those that are due.
Each child is seen to on its own: a child whose watching raises is logged and left to the next pass, and the rest are still watched. What is acted on is the state a child is in, not how it came to be in it, so a child with a restart policy that is down and waiting for nothing is given a restart to wait for.
Arguments
now: The current time.