Skip to content

Commit bfed332

Browse files
committed
Merge branch 'mmacklin/safe-rename-windows' into 'main'
Add a safe_rename() to update the Warp kernel cache to avoid transient access denied issues See merge request omniverse/warp!919
2 parents a55097a + 1d31d43 commit bfed332

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
([GH-386](https://github.com/NVIDIA/warp/issues/386)).
2323
- Array overwrite tracking: Fix issue with not marking arrays passed to `wp.atomic_add()`, `wp.atomic_sub()`,
2424
`wp.atomic_max()`, or `wp.atomic_min()` as being written to ([GH-378](https://github.com/NVIDIA/warp/issues/378)).
25+
- Fix for occasional failure to update .meta files into Warp kernel cache on Windows
26+
- Mark kernel arrays as written to when passed to `wp.atomic_add()` or `wp.atomic_sub()`
2527

2628
## [1.5.0] - 2024-12-02
2729

warp/context.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import ast
99
import ctypes
10+
import errno
1011
import functools
1112
import hashlib
1213
import inspect
@@ -17,6 +18,7 @@
1718
import os
1819
import platform
1920
import sys
21+
import time
2022
import types
2123
import typing
2224
import weakref
@@ -2131,12 +2133,34 @@ def load(self, device, block_dim=None) -> ModuleExec:
21312133
# -----------------------------------------------------------
21322134
# update cache
21332135

2134-
try:
2135-
# Copy process-specific build directory to a process-independent location
2136-
os.rename(build_dir, module_dir)
2137-
except (OSError, FileExistsError):
2138-
# another process likely updated the module dir first
2139-
pass
2136+
def safe_rename(src, dst, attempts=5, delay=0.1):
2137+
for i in range(attempts):
2138+
try:
2139+
os.rename(src, dst)
2140+
return
2141+
except FileExistsError:
2142+
return
2143+
except OSError as e:
2144+
if e.errno == errno.ENOTEMPTY:
2145+
# if directory exists we assume another process
2146+
# got there first, in which case we will copy
2147+
# our output to the directory manually in second step
2148+
return
2149+
else:
2150+
# otherwise assume directory creation failed e.g.: access denied
2151+
# on Windows we see occasional failures to rename directories due to
2152+
# some process holding a lock on a file to be moved to workaround
2153+
# this we make multiple attempts to rename with some delay
2154+
if i < attempts - 1:
2155+
time.sleep(delay)
2156+
else:
2157+
print(
2158+
f"Could not update Warp cache with module binaries, trying to rename {build_dir} to {module_dir}, error {e}"
2159+
)
2160+
raise e
2161+
2162+
# try to move process outputs to cache
2163+
safe_rename(build_dir, module_dir)
21402164

21412165
if os.path.exists(module_dir):
21422166
if not os.path.exists(binary_path):

0 commit comments

Comments
 (0)