From 64ef488ce4bee877e2db987ef001c9724073eef1 Mon Sep 17 00:00:00 2001 From: Marius Ciepluch <11855163+norandom@users.noreply.github.com> Date: Sat, 26 Sep 2026 07:44:33 +0200 Subject: [PATCH] test(cpg-budget): a process vanishing mid-read is the success case too Reading /proc//stat for a process that is reaped during the read raises ProcessLookupError (ESRCH), not FileNotFoundError. The previous race fix caught only the latter, so the hanging-process-group test failed twice today under full-suite load. It passed alone. The disappearance is exactly what the test asserts. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo --- tests/test_cpg_budget.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_cpg_budget.py b/tests/test_cpg_budget.py index 25b1fd8..d2df9a9 100644 --- a/tests/test_cpg_budget.py +++ b/tests/test_cpg_budget.py @@ -68,11 +68,12 @@ while True: time.sleep(1) status = Path(f"/proc/{pid}/stat") for _ in range(30): # Read, never check-then-read: a killed process can be reaped between the two, and its - # disappearing is exactly the outcome this test wants, not an error. + # disappearing is exactly the outcome this test wants, not an error. It can vanish before the + # open (FileNotFoundError) or during the read, which the kernel reports as ESRCH. try: if status.read_text().split()[2] == "Z": break - except FileNotFoundError: + except (FileNotFoundError, ProcessLookupError): break time.sleep(0.005) else: