You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NamedTemporaryFile doesn't issue a ResourceWarning when left unclosed on POSIX #126639
I don't see how that's related? The resource delete on __del__ is a last resort, and it needs to issue a ResourceWarning so that code that fails to finalise explicitly can be detected
Activity
graingert commentedon Nov 10, 2024
I think this
__del__needs to issue the resource warning:cpython/Lib/tempfile.py
Lines 471 to 472 in 450db61
picnixz commentedon Nov 10, 2024
graingert commentedon Nov 10, 2024
I don't see how that's related? The resource delete on
__del__is a last resort, and it needs to issue a ResourceWarning so that code that fails to finalise explicitly can be detectedpicnixz commentedon Nov 10, 2024
Ah sorry, I misunderstood the "open again" in the sense that you can leave the descriptor hanging. My bad. However, non-named temporary files say:
Should implicit close emit a warning in this case? Actually, why is there a warning on Windows?
graingert commentedon Nov 10, 2024
Yes, all implicit closing of resources on GC should issue a ResourceWarning
graingert commentedon Nov 10, 2024
I suspect the way to go here is to replace _TemporaryFileCloser with a weakref.finalize
tomasr8 commentedon Nov 10, 2024
Looks like it,
TemporaryDirectoryis doing something similar:cpython/Lib/tempfile.py
Lines 885 to 888 in 450db61
pythongh-126639: Add ResourceWarning to NamedTemporaryFile
pythongh-126639: Add ResourceWarning to NamedTemporaryFile
gh-126639: Add ResourceWarning to NamedTemporaryFile (#126677)
picnixz commentedon Dec 19, 2024
Categorizing it as a feature as per #126677 (comment).
pythongh-126639: Add ResourceWarning to NamedTemporaryFile (python#12…