Fix PermissionError deleting locked HDF5 cache on Windows

When the hdf5 serializer constructor fails on an existing
file, the HDF5 C library retains the file handle on Windows.
Force gc.collect() before os.remove() to release it, and
catch PermissionError to skip the cache gracefully if the
file is still locked.

Generated with the assistance of an AI coding tool.
This commit is contained in:
Ryan Schultz
2026-03-29 09:51:15 -05:00
parent 0ed96d32dd
commit 46640722b4
2 changed files with 9 additions and 1 deletions
+8 -1
View File
@@ -18,6 +18,7 @@
from __future__ import annotations from __future__ import annotations
import gc
import hashlib import hashlib
import os import os
import shutil import shutil
@@ -170,7 +171,13 @@ class IfcStore:
# No point to trying again the same operation. # No point to trying again the same operation.
return return
os.remove(IfcStore.cache_path) # Force GC to release any dangling HDF5 C-level file handle (Windows).
gc.collect()
try:
os.remove(IfcStore.cache_path)
except PermissionError as e:
print(f"Could not delete locked cache file '{cache_path.name}': {str(e)}. Skipping cache.")
return
try: try:
IfcStore.cache = ifcopenshell.geom.serializers.hdf5( IfcStore.cache = ifcopenshell.geom.serializers.hdf5(
IfcStore.cache_path, cache_settings, serializer_settings IfcStore.cache_path, cache_settings, serializer_settings
+1
View File
@@ -25,6 +25,7 @@ import bmesh
import bpy import bpy
import mathutils import mathutils
import numpy as np import numpy as np
from bpy_extras import view3d_utils
from mathutils import Vector from mathutils import Vector
import bonsai.core.tool import bonsai.core.tool