Skip to main content

Module fork

Module fork 

Source
Expand description

The fork servers, agent side (see archive/PROJECT.md, How Python tasks are started: the fork server): started with the worker, two per interpreter (one preloading the configured libraries, a bare one), each restarted with backoff when it dies; a Python task or a parse job asks the preloaded one to fork its runner, then the bare one, and is spawned when neither can (a task with preload=False asks only the bare one, one with fresh_process=True neither).

A forked runner is not the agent’s child: its shim (forked by the fork server) is its parent and reports on a status socket the agent passes with the request, process_started (the PID, once the process group exists) and process_exited. The shim reaps the process only when the agent closes that socket (GroupHold), so its PID and group can’t be reused while the agent may still signal them.

The thin operating-system layer under crate::launch, exercised by the integration tests (tests/fork.rs); the backoff is unit-tested.

Structs§

ForkBackoff
How a fork server’s restarts are spaced.
ForkConfig
An interpreter’s fork server settings ([interpreters.<name>] with fork_server = true).
ForkMetrics
Where the fork servers’ states and fallbacks are counted.
ForkServers
An interpreter’s fork servers, preloaded first (cheap to clone; clones share them).
ForkSetup
How to start an interpreter’s fork servers.
Forked
A runner forked from a fork server, with the agent’s ends of its sockets.
ForkedProcess
A forked runner process: its group, its shim’s status socket, and its output.
GroupHold
A copy of the agent’s end of a forked process’s status socket: while any copy is open, the shim keeps the ended process unreaped, so its PID and group stay its own. Dropped once nothing may signal the group any more (after the memory watchdog stopped), on every path.

Enums§

Cause
Why a fork server came up disabled.
Fallback
Why a task wasn’t forked by one fork server (the metric’s reason).
Kind
Which of an interpreter’s two fork servers.

Constants§

BACKOFF_FIRST
The first wait before restarting a fork server that died or couldn’t start.
BACKOFF_MAX
The longest wait before a restart.
BACKOFF_RESET_AFTER
How long a fork server must have been up for the backoff to start again from BACKOFF_FIRST.
FORK_ANSWER_TIMEOUT
How long a fork server may take to answer a fork request.
FORK_SERVER_DISABLED
The worker warning’s kind for a disabled fork server.
PRELOAD_TIMEOUT
How long a fork server may take to preload its libraries and answer.

Functions§

retried
Whether a fork server disabled for cause, failing for failing_for since its first failure, is started again: a failing import within window (long enough for what isn’t ready at a pod’s start; a failure still there after it is lasting: a missing package, a typo).
servers_memory
The memory of the processes in groups together (PSS); None when one’s can’t be read.