Skip to content

Commit a43094a

Browse files
committed
delay tmp dir cleanup
for source code discovery during weights conversion
1 parent 592c3ed commit a43094a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

bioimageio/core/digest_spec.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def import_callable(
8484
return c
8585

8686

87+
tmp_dirs_in_use: List[TemporaryDirectory[str]] = []
88+
"""keep global reference to temporary directories created during import to delay cleanup"""
89+
90+
8791
def _import_from_file_impl(
8892
source: FileSource, callable_name: str, **kwargs: Unpack[HashKwargs]
8993
):
@@ -111,7 +115,14 @@ def _import_from_file_impl(
111115
td_kwargs: Dict[str, Any] = (
112116
dict(ignore_cleanup_errors=True) if sys.version_info >= (3, 10) else {}
113117
)
118+
if sys.version_info >= (3, 12):
119+
td_kwargs["delete"] = False
120+
114121
tmp_dir = TemporaryDirectory(**td_kwargs)
122+
# keep global ref to tmp_dir to delay cleanup until program exit
123+
# TODO: remove for py >= 3.12, when delete=False works
124+
tmp_dirs_in_use.append(tmp_dir)
125+
115126
module_path = Path(tmp_dir.name) / module_name
116127
if reader.original_file_name.endswith(".zip") or is_zipfile(reader):
117128
module_path.mkdir()

0 commit comments

Comments
 (0)