Eryk Sun <eryk...@gmail.com> added the comment:

> Why do we need to use this O_TEMPORARY flag at all?

Using the O_TEMPORARY flag isn't necessary, but it's usually preferred because 
it ensures the file gets deleted even if the process is terminated abruptly. 
However, it opens the file with delete access, and most Windows programs don't 
share delete access for normal file opens. This can be worked around in Python 
code by using an opener that calls CreateFileW with delete-access sharing. But 
it can't be worked around in general. 

I prefer to provide a way to omit O_TEMPORARY, but still use it by default. 
When it's omitted, I'd also like to be able to close the file within the 
context block without deleting it, for which one use case is to reopen the file 
in a program that doesn't share read or write access. A new delete_on_close 
option would support this case, in addition to providing a way to omit the 
O_TEMPORARY flag. For example:
    
    with tempfile.NamedTemporaryFile(delete_on_close=False) as f:
        f.close()
        subprocess.run([cmd, f.name])

The file will still be deleted by the context manager, but the tradeoff is that 
it's not as reliable as the default delete-on-close behavior that uses the 
O_TEMPORARY flag.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue14243>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to