diff --git a/scripts/pack_probe.py b/scripts/pack_probe.py index 7c466c7b1..59cef3c2e 100644 --- a/scripts/pack_probe.py +++ b/scripts/pack_probe.py @@ -29,7 +29,8 @@ or holds under another path. Each core_probe run holds the host's probe lock (~/.local/state/retrobios/ probe.lock, RETROBIOS_PROBE_LOCK) and releases it before the next: other -probes run between ours. Building and extracting the pack take no lock. +probes run between ours. core_probe is told it is held +(RETROBIOS_PROBE_LOCK_HELD). Building and extracting the pack take no lock. Usage: python scripts/pack_probe.py run --platform retroarch [--system sony-playstation] @@ -85,7 +86,9 @@ VERDICTS = ("boots", "bios_error", "crash", "hang", "unknown") MAX_ROUNDS = 6 PROBE_TIMEOUT = 900 IDLE_WAIT = 1800 -PROBE_LOCK = Path(os.environ.get("RETROBIOS_PROBE_LOCK") +PROBE_LOCK_ENV = "RETROBIOS_PROBE_LOCK" +PROBE_LOCK_HELD_ENV = "RETROBIOS_PROBE_LOCK_HELD" +PROBE_LOCK = Path(os.environ.get(PROBE_LOCK_ENV) or Path.home() / ".local" / "state" / "retrobios" / "probe.lock") EXIT_BUSY = 3 @@ -484,8 +487,10 @@ def core_probe(argv: list[str], staged: set[str], layout: Layout, work: Path) -> with probe_lock(): if "--record" in argv: wait_idle() + # core_probe takes the same lock unless told its caller holds it. proc = subprocess.run(command, capture_output=True, text=True, check=False, cwd=ROOT, - timeout=PROBE_TIMEOUT * 2 + 120) + timeout=PROBE_TIMEOUT * 2 + 120, + env={**os.environ, PROBE_LOCK_HELD_ENV: "1", PROBE_LOCK_ENV: str(PROBE_LOCK)}) record = None if proc.returncode == 0: try: diff --git a/tests/test_pack_probe.py b/tests/test_pack_probe.py index ec02bdf79..4c86ff38e 100644 --- a/tests/test_pack_probe.py +++ b/tests/test_pack_probe.py @@ -270,6 +270,8 @@ class Lock(unittest.TestCase): def fake_run(command, **kwargs): held.append(try_lock()) + self.assertEqual(kwargs["env"]["RETROBIOS_PROBE_LOCK_HELD"], "1") + self.assertEqual(kwargs["env"]["RETROBIOS_PROBE_LOCK"], str(lock)) return subprocess.CompletedProcess(command, 2, "", "refused") lay = layout({"a.bin": 1}) diff --git a/wiki/tools.md b/wiki/tools.md index 09db531fc..0910a2f3d 100644 --- a/wiki/tools.md +++ b/wiki/tools.md @@ -1081,7 +1081,8 @@ installs it, starts that platform's games. A maintainer starts it, nothing runs it on a schedule. It takes the host's probe lock (`~/.local/state/retrobios/probe.lock`, `RETROBIOS_PROBE_LOCK`) around each `core_probe` run and releases it before the next, so other probes run between -its runs. Never wrap the whole command in `flock`: +its runs, and tells `core_probe` it holds it (`RETROBIOS_PROBE_LOCK_HELD=1`). +Never wrap the whole command in `flock`: ```bash python scripts/pack_probe.py run --platform retroarch