[docs] [issue4928] Problem with tempfile.NamedTemporaryFile

Eryk Sun report at bugs.python.org
Sat Feb 20 10:53:56 EST 2016

Eryk Sun added the comment:

Maybe a note could be added to suggest using a SIGTERM signal handler (e.g. the handler could raise a SIGTERM exception):

POSIX: The file will not be deleted if the process is terminated abruptly by a signal. A process may register a SIGTERM handler to ensure that the file is deleted, but SIGKILL cannot be handled. Windows: the file will be deleted when it is closed, even if the process is terminated.

Note that for Windows it is possible to make the file permanent, but it's probably not common enough to bother with documenting this. Currently the documentation states that "[w]hether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later)". Actually on Windows the file can be opened again while the named temporary file is still open. You can use an opener that calls os.open with the O_TEMPORARY flag. But the opener can also call _winapi.CreateFile with read, write, and delete sharing. If DELETE access is requested this handle can be used to make the file permanent via SetFileInformationByHandle.

assignee:  -> docs at python
components: +Documentation
nosy: +docs at python, eryksun
versions: +Python 3.5, Python 3.6 -Python 3.1, Python 3.2

Python tracker <report at bugs.python.org>

More information about the docs mailing list