spawn
Starting the compute's children as processes.
How a Compute runs its pod and its patient-data API: as separate child
processes it can start, watch and stop independently of each other (ADR
0011). One implementation for every host. The only thing a host may vary is
what runs inside a child before its real work begins -- the bootstrap on a
ChildSpec -- which is how the desktop app registers its progress hooks and
token queue in the child, and Docker registers nothing.
Module
Functions
child_context
def child_context() ‑> multiprocessing.context.SpawnContext:The multiprocessing context every compute child is started under.
Always spawn, whatever the platform default: a child is a fresh
interpreter, not a copy of its host. Anything a host hands to a child
that carries a lock (a queue, an event) must be built under this same
context, because a queue built under fork cannot be passed to a
spawn-started process. Hosts build such objects through this function
rather than naming the start method themselves.
spawn_child
def spawn_child( spec: ChildSpec, *, daemon: bool = True, environment: Mapping[str, str] | None = None,) ‑> multiprocessing.process.BaseProcess:Start a child process for spec.
Started under child_context, so the child is a fresh interpreter rather
than a copy of the host. multiprocessing.freeze_support() remains the
host's responsibility, in its main module.
Arguments
spec: What to run.daemon: Whether the child is torn down automatically when the host exits. A daemon process may not start processes of its own, so this suits the API child but not the pod, which does.environment: Environment variables the child should inherit in addition to the host's, set only for the duration of the spawn.
Returns The started process.
Classes
ChildSpec
class ChildSpec( name: str, target: Callable[..., None], args: tuple[Any, ...] = (), bootstrap: Callable[..., None] | None = None, bootstrap_args: tuple[Any, ...] = (),):What to run in a child process, and how to prepare it.
Everything here reaches the child by pickling, so target and
bootstrap must be module-level functions and the arguments plain data.
Arguments
name: The process name, for logs and status.target: The child's main.args: Positional arguments fortarget.bootstrap: Optional host-specific setup run in the child beforetarget. The one place hosts differ.bootstrap_args: Positional arguments forbootstrap.
Variables
- static
args : tuple[typing.Any, ...]
- static
bootstrap : collections.abc.Callable[..., None] | None
- static
bootstrap_args : tuple[typing.Any, ...]
- static
name : str
- static
target : collections.abc.Callable[..., None]