[issue42830] tempfile mkstemp() leaks file descriptors if os.close() is not called
Isaac Young
report at bugs.python.org
Thu Jan 28 06:03:11 EST 2021
Isaac Young <isyoung at pm.me> added the comment:
Perhaps the documentation should be more explicit, but I wouldn't say this is an issue. Both mkstemp and mkdtemp are low level functions which are intended to have this kind of flexibility.
The os.unlink, and the equivalent os.remove, are POSIX defined functions which always deletes the name from the filesystem but the file will remain in memory so long as there are file descriptors referencing it. So using os.close(file_descriptor) is actually how you are expected to use this API.
Is there any reason you don't want to use [Named]TemporaryFile? They are high level interfaces which handle the cleanup.
----------
nosy: +StillSubjectToChange
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42830>
_______________________________________
More information about the Python-bugs-list
mailing list