schedr.runner.usage

What an ended child used (rusage), read by its parent without reaping it.

The shim keeps its ended process a zombie until the agent closes the status socket (so the PID isn’t reused), which os.wait4 can’t do. The waitid system call can: with WNOWAIT it fills the rusage its fifth argument points to and leaves the zombie, but Python’s os.waitid doesn’t pass that argument, so the call goes through ctypes.

It must never break the shim: prepare() loads everything in the fork server, before any fork; read() is called only after the exit was seen (it returns at once), makes no allocation that can fail halfway, and gives None for anything unexpected: an unknown CPU architecture, a failing call, any exception.

class schedr.runner.usage.Reader(syscall, number)

Bases: object

Reads an ended child’s usage; set up by prepare() before forking.

Parameters:
  • syscall (Any)

  • number (int)

read(pid)

The usage of an ended child that is still a zombie, which it stays.

Parameters:

pid (int) – The child, already seen ended (os.waitid with WNOWAIT).

Returns:

The ProcessUsage fields, or None if they can’t be read.

Return type:

dict[str, int] | None

schedr.runner.usage.prepare()

Sets up the reader in the fork server, before any fork.

Returns:

The reader, or None on a CPU architecture whose waitid number isn’t known, or if libc can’t be loaded.

Return type:

Reader | None