bim.purge_hdf5_cache to skip currently loaded cache

Previously it would fail with:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'bonsai\\bim\\data\\cache\\988c190483ae6bab7cf6b00cee78694d.h5'
This commit is contained in:
Andrej730
2024-08-27 11:59:56 +05:00
parent 27aee31adf
commit 48f0dc6a00
3 changed files with 12 additions and 2 deletions
+6 -1
View File
@@ -57,5 +57,10 @@ class TestPurgeHdf5Cache(NewFile):
test_file = cache_dir / "test.h5"
test_file.parent.mkdir(parents=True, exist_ok=True)
test_file.touch()
# Ensure it can skip currently loaded cache.
loaded_file_path = test_file.with_stem("test_loaded")
loaded_file = open(loaded_file_path, "w")
subject.purge_hdf5_cache()
assert not [f for f in cache_dir.iterdir() if f.suffix == ".h5"]
assert [f for f in cache_dir.iterdir() if f.suffix == ".h5"] == [loaded_file_path]