Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tools/drive/drive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Expand Down
Loading