[issue14243] tempfile.NamedTemporaryFile not particularly useful on Windows

Paul Moore report at bugs.python.org
Fri Apr 30 11:12:03 EDT 2021


Paul Moore <p.f.moore at gmail.com> added the comment:

Looking at the various comments, I think we have 5 votes for deleting on CM exit when used as a CM, and no change in behaviour otherwise (me, Zachary, Ethan, Jason and Steve). Steve also wants O_TEMPORARY to be removed, which doesn't seem controversial among this group of people.

Eryk has argued for a delete_on_close flag that would need to be explicitly set to False, retaining the use of O_TEMPORARY in the default case, but there doesn't seem to be a lot of support for that.

If I've misrepresented anyone's view, please speak up!

I didn't look back at the stuff from 2013 and earlier, I'll admit.

I do think this needs care to implement (and document!) correctly. For example, consider the following case:

    ntf = NamedTemporaryFile()
    # Do some stuff (1)
    with ntf:
        # Do some stuff (2)
    # Do some followup stuff

I assume we'd want a close in (1) to delete the file, but a close in (2) to leave it open until the CM exit.

Evgeny, would you be willing to update your PR (including adding the docs change, and tests to catch as many edge cases as you can think up) to match this behaviour?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue14243>
_______________________________________


More information about the Python-bugs-list mailing list