File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff 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+
8791def _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 ()
You can’t perform that action at this time.
0 commit comments