Issue 34157: NamedTemporaryFile can leave temporary files behind (original) (raw)
I think is unrelated, or at least not the whole story.
These are samples of tracebacks I see when the file is left behind:
Traceback (most recent call last): File "test-tmpfile.py", line 4, in with tempfile.NamedTemporaryFile(dir='.'): File "/opt/python/lib/python3.8/tempfile.py", line 548, in NamedTemporaryFile (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type) File "/opt/python/lib/python3.8/tempfile.py", line 258, in _mkstemp_inner fd = _os.open(file, flags, 0o600) KeyboardInterrupt
Traceback (most recent call last): File "test-tmpfile.py", line 4, in with tempfile.NamedTemporaryFile(dir='.'): File "/opt/python/lib/python3.8/tempfile.py", line 548, in NamedTemporaryFile (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type) File "/opt/python/lib/python3.8/tempfile.py", line 269, in _mkstemp_inner return (fd, _os.path.abspath(file)) File "/opt/python/lib/python3.8/posixpath.py", line 371, in abspath path = os.fspath(path) KeyboardInterrupt
Traceback (most recent call last): File "test-tmpfile.py", line 4, in with tempfile.NamedTemporaryFile(dir='.'): File "/opt/python/lib/python3.8/tempfile.py", line 548, in NamedTemporaryFile (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type) File "/opt/python/lib/python3.8/tempfile.py", line 269, in _mkstemp_inner return (fd, _os.path.abspath(file)) File "/opt/python/lib/python3.8/posixpath.py", line 378, in abspath return normpath(path) File "/opt/python/lib/python3.8/posixpath.py", line 355, in normpath if comp in (empty, dot): KeyboardInterrupt
In all cases the interrupt happened in the NamedTemporaryFile function, so before enter/exit would have chance to do its job.