mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
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:
@@ -18,6 +18,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import gc
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
@@ -170,7 +171,13 @@ class IfcStore:
|
||||
# No point to trying again the same operation.
|
||||
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:
|
||||
IfcStore.cache = ifcopenshell.geom.serializers.hdf5(
|
||||
IfcStore.cache_path, cache_settings, serializer_settings
|
||||
|
||||
@@ -25,6 +25,7 @@ import bmesh
|
||||
import bpy
|
||||
import mathutils
|
||||
import numpy as np
|
||||
from bpy_extras import view3d_utils
|
||||
from mathutils import Vector
|
||||
|
||||
import bonsai.core.tool
|
||||
|
||||
Reference in New Issue
Block a user