Coverage for src/lilbee/runtime/shard_process.py: 100%
13 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-11-06 08:17 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-11-06 08:17 +0000
1"""What a fan-out worker process was told about its own slice of the machine.
3A worker pins its card, its engine slot and its CPU share. These values live
4here, in plain Python state, and not in ``os.environ``: ``setenv`` reallocates
5the C ``environ`` array, and a native thread that reads it at that moment
6(pyarrow, lancedb) can fault. A worker has native threads as soon as its
7imports finish, so no variable can be written in it safely.
9The readers take the value from here. An engine child gets the card pin in its
10own ``env=`` at spawn.
11"""
13from __future__ import annotations
15from dataclasses import dataclass, field
16from pathlib import Path
19@dataclass
20class ShardProcessState:
21 """The slice values of this process; every field is unset outside a worker."""
23 engine_dir: Path | None = None
24 cpu_quota: int | None = None
25 visible_devices: dict[str, str] = field(default_factory=dict)
27 def bind(self, engine_dir: Path, cpu_quota: int, visible_devices: dict[str, str]) -> None:
28 """Record the slice. Called once, first, by the worker's main thread."""
29 self.engine_dir = engine_dir
30 self.cpu_quota = cpu_quota
31 self.visible_devices = dict(visible_devices)
34shard_process = ShardProcessState()