Skip to content

Commit 4aa42e0

Browse files
cpcloudclaude
andcommitted
Retry os.replace on Windows PermissionError
On Windows, os.replace raises PermissionError when another process has the target file open. Add exponential backoff retry (5 attempts) for the concurrent-writers case. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cd10cc9 commit 4aa42e0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cuda_core/cuda/core/utils/_program_cache.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,16 @@ def __setitem__(self, key: object, value: object) -> None:
575575
fh.write(record)
576576
fh.flush()
577577
os.fsync(fh.fileno())
578-
os.replace(tmp_path, target)
578+
# On Windows, os.replace can raise PermissionError when another
579+
# process holds the target open. Retry a few times with backoff.
580+
for attempt in range(5):
581+
try:
582+
os.replace(tmp_path, target)
583+
break
584+
except PermissionError:
585+
if attempt == 4:
586+
raise
587+
time.sleep(0.01 * (2**attempt))
579588
except BaseException:
580589
with contextlib.suppress(FileNotFoundError):
581590
tmp_path.unlink()

0 commit comments

Comments
 (0)