Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf9585e2

Browse files
gh-93353: Fix importlib.resources._tempfile() finalizer (GH-93377)
Fix the importlib.resources.as_file() context manager to remove thetemporary file if destroyed late during Python finalization: keep alocal reference to the os.remove() function. Patch by Victor Stinner.(cherry picked from commit443ca73)Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent58277de commitf9585e2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

‎Lib/importlib/_common.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ def from_package(package):
8080

8181

8282
@contextlib.contextmanager
83-
def_tempfile(reader,suffix=''):
83+
def_tempfile(reader,suffix='',
84+
# gh-93353: Keep a reference to call os.remove() in late Python
85+
# finalization.
86+
*,_os_remove=os.remove):
8487
# Not using tempfile.NamedTemporaryFile as it leads to deeper 'try'
8588
# blocks due to the need to close the temporary file to work on Windows
8689
# properly.
@@ -92,7 +95,7 @@ def _tempfile(reader, suffix=''):
9295
yieldpathlib.Path(raw_path)
9396
finally:
9497
try:
95-
os.remove(raw_path)
98+
_os_remove(raw_path)
9699
exceptFileNotFoundError:
97100
pass
98101

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix the:func:`importlib.resources.as_file` context manager to remove the
2+
temporary file if destroyed late during Python finalization: keep a local
3+
reference to the:func:`os.remove` function. Patch by Victor Stinner.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp