From 3f2540182cd50d16dba111b35e1122b105983380 Mon Sep 17 00:00:00 2001 From: R Date: Fri, 20 Nov 2026 02:45:58 -0300 Subject: [PATCH] tools: drive_test survives Windows' replace-while-open race: the stand-in retries its record's replace and the test retries its read on PermissionError, which failed the MSVC 14.5 job at random --- tools/drive/drive_test.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/drive/drive_test.py b/tools/drive/drive_test.py index 55202398..b66da720 100755 --- a/tools/drive/drive_test.py +++ b/tools/drive/drive_test.py @@ -51,6 +51,13 @@ def save(): with open(record + '.tmp', 'w') as file: json.dump(recorded, file) + # On Windows a reader that has the record open makes the replace fail for that moment. + for _ in range(500): + try: + os.replace(record + '.tmp', record) + return + except PermissionError: + time.sleep(0.01) os.replace(record + '.tmp', record) @@ -143,7 +150,12 @@ def recorded(self, holds=lambda record: True, seconds: float = 30) -> dict: deadline = time.monotonic() + seconds while time.monotonic() < deadline: if self.record.is_file(): - record = json.loads(self.record.read_text()) + try: + record = json.loads(self.record.read_text()) + except PermissionError: + # Windows: the stand-in is replacing the record at this moment. + time.sleep(0.05) + continue if holds(record): return record time.sleep(0.05)