[issue4928] Problem with tempfile.NamedTemporaryFile
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@python components: +Documentation nosy: +docs@python, eryksun versions: +Python 3.5, Python 3.6 -Python 3.1, Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue4928> _______________________________________
participants (1)
-
Eryk Sun