From b3ab4344d11edd890916be3526b07362182fb172 Mon Sep 17 00:00:00 2001 From: Catherine Devlin Date: Wed, 19 May 2021 10:21:03 -0400 Subject: [PATCH] bpo-4928: Document NamedTemporaryFile non-deletion after SIGKILL (#26198) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bpo-4928 Document NamedTemporaryFile non-deletion after SIGKILL * 📜🤖 Added by blurb_it. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> --- Doc/library/tempfile.rst | 3 +++ Lib/tempfile.py | 4 ++++ .../next/Library/2021-05-17-21-05-06.bpo-4928.Ot2yjO.rst | 1 + 3 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-05-17-21-05-06.bpo-4928.Ot2yjO.rst diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index 29702520367..49396b5f4bd 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -87,6 +87,9 @@ The module defines the following user-callable items: attribute is the underlying true file object. This file-like object can be used in a :keyword:`with` statement, just like a normal file. + On POSIX (only), a process that is terminated abruptly with SIGKILL + cannot automatically delete any NamedTemporaryFiles it created. + .. audit-event:: tempfile.mkstemp fullpath tempfile.NamedTemporaryFile .. versionchanged:: 3.8 diff --git a/Lib/tempfile.py b/Lib/tempfile.py index efcf7a7fb3b..8570c3ba062 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -532,6 +532,10 @@ def NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None, Returns an object with a file-like interface; the name of the file is accessible as its 'name' attribute. The file will be automatically deleted when it is closed unless the 'delete' argument is set to False. + + On POSIX, NamedTemporaryFiles cannot be automatically deleted if + the creating process is terminated abruptly with a SIGKILL signal. + Windows can delete the file even in this case. """ prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir) diff --git a/Misc/NEWS.d/next/Library/2021-05-17-21-05-06.bpo-4928.Ot2yjO.rst b/Misc/NEWS.d/next/Library/2021-05-17-21-05-06.bpo-4928.Ot2yjO.rst new file mode 100644 index 00000000000..359f8015821 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-05-17-21-05-06.bpo-4928.Ot2yjO.rst @@ -0,0 +1 @@ +Documented existing behavior on POSIX: NamedTemporaryFiles are not deleted when creating process is killed with SIGKILL \ No newline at end of file