Skip to content

lablink_client_service.monitoring.samplers.processes

Process sampler.

Walks /proc/*/cmdline and returns the set of allowlisted process names currently present. We read cmdline (not comm) because SLEAP's GUI ships entry-point shim scripts: their /proc//comm reads "python3", but argv[0] is the real binary path. comm-based matching never fires.

Three SLEAP invocation shapes are recognised, normalised to the canonical names in the allowlist:

  1. Direct entry-point script — sleap-label, sleap-train, sleap-track. Matched on argv[0] basename. Covers the GUI binary itself (sleap-label) and any hand-run CLI.
  2. sleap <subcommand> — e.g. sleap track …. The SLEAP GUI uses this shape for inference (sleap/gui/learning/runners.py:541).
  3. <python> -m sleap.cli <subcommand> — the SLEAP GUI uses this shape for training, deliberately (PyTorch Lightning DDP needs main.spec set, which entry-point scripts don't provide; sleap/gui/learning/runners.py:1311). argv[0] is the python interpreter.
Source code in packages/client/src/lablink_client_service/monitoring/samplers/processes.py
def sample(allowlist: Iterable[str], proc_root: str = "/proc") -> Set[str]:
    wanted = set(allowlist)
    seen: Set[str] = set()
    try:
        entries = os.listdir(proc_root)
    except OSError:
        return seen

    for name in entries:
        if not name.isdigit():
            continue
        parts = _read_cmdline(os.path.join(proc_root, name, "cmdline"))
        if parts is None:
            continue
        seen |= _classify(parts, wanted)
        if seen >= wanted:
            break
    return seen