schedr.runner.fork_server¶
Fork server mode: preload libraries once, then fork a runner process per request.
The agent starts the fork server when the worker starts and sends it the preload list. Per
attempt it sends fork with four descriptors: the process’s channel, its stdout and stderr,
and a status socket. The fork server forks a shim, and the shim forks the process:
the process runs the normal runner code (parse / task) on its own channel, as a
spawned runner does; the shim reports its PID once its process group exists, then its exit
status, and reaps it when the agent closes the status socket, so the PID isn’t reused while
the agent may still signal the group (see archive/PROJECT.md, How Python tasks are started: the fork
server). Linux only.
- schedr.runner.fork_server.FDS = 4¶
channel, stdout, stderr, status socket.
- Type:
The descriptors a
forkrequest carries
- schedr.runner.fork_server.FORKED_MODES = ('parse', 'task')¶
The modes a forked process can run.
- schedr.runner.fork_server.thread_names()¶
The names of the process’s threads besides the main one.
- Returns:
Each other thread’s name (
/proc/self/task/<tid>/comm), by thread ID.- Return type:
list[str]
- schedr.runner.fork_server.run_fork_server(channel, request, *, threads=<function thread_names>)¶
Preloads the libraries, then forks a process per request until the agent closes.
A disabled fork server stays until the agent closes the channel too, answering every request with
fork_failed: exiting with a request unread would reset the connection, and the agent could lose thefork_server_disabledbefore it.- Parameters:
channel (Channel) – The channel to the agent.
request (Mapping[str, Any]) – The
fork_serverrequest (the preload list).threads (Callable[[], list[str]]) – Lists the threads besides the main one (replaced in tests).
- Returns:
0, once the agent closed the channel.
- Raises:
ProtocolError – For a message that isn’t a valid
forkrequest.- Return type:
int
- type schedr.runner.fork_server.Disabled = tuple[str, list[str]] | None¶
Why the fork server is disabled and the threads besides the main one;
Noneif it isn’t.