Fix windows async np.save bug (#19218)

Signed-off-by: eric80739 <68726577+eric80739@users.noreply.github.com>
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
eric80739 2025-02-13 12:38:56 +08:00 committed by GitHub
parent fb444bca1f
commit d6a07ee78a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -714,8 +714,8 @@ def save_dataset_cache_file(prefix, path, x, version):
if is_dir_writeable(path.parent): if is_dir_writeable(path.parent):
if path.exists(): if path.exists():
path.unlink() # remove *.cache file if exists path.unlink() # remove *.cache file if exists
np.save(str(path), x) # save cache for next time with open(str(path), "wb") as file: # context manager here fixes windows async np.save bug
path.with_suffix(".cache.npy").rename(path) # remove .npy suffix np.save(file, x)
LOGGER.info(f"{prefix}New cache created: {path}") LOGGER.info(f"{prefix}New cache created: {path}")
else: else:
LOGGER.warning(f"{prefix}WARNING ⚠️ Cache directory {path.parent} is not writeable, cache not saved.") LOGGER.warning(f"{prefix}WARNING ⚠️ Cache directory {path.parent} is not writeable, cache not saved.")