From f42271054da01678683f57c1efbd1940b9a582d1 Mon Sep 17 00:00:00 2001 From: Gregory Shimansky Date: Thu, 21 Nov 2024 08:36:26 -0800 Subject: [PATCH] Fixed exception on windows when contention happens in file cache Signed-off-by: Gregory Shimansky --- python/triton/runtime/cache.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/triton/runtime/cache.py b/python/triton/runtime/cache.py index 62895508b0..4df2296acc 100644 --- a/python/triton/runtime/cache.py +++ b/python/triton/runtime/cache.py @@ -131,7 +131,15 @@ def put(self, data, filename, binary=True) -> str: f.write(data) # Replace is guaranteed to be atomic on POSIX systems if it succeeds # so filepath cannot see a partial write - os.replace(temp_path, filepath) + try: + os.replace(temp_path, filepath) + except PermissionError: + # Ignore PermissionError on Windows because it happens when another process already + # put a file into the cache and locked it by opening it. + if os.name == "nt": + os.remove(temp_path) + else: + raise os.removedirs(temp_dir) return filepath