Eryk Sun <eryk...@gmail.com> added the comment:
Your example uses delete=False. In Windows, the provision about reopening the file while it's open applies to delete=True. With the latter, the file is opened with the O_TEMPORARY flag. At the OS level, this flag modifies the CreateFileW() call as follows: dwDesiredAccess |= DELETE; dwShareMode |= FILE_SHARE_DELETE; dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; Because the open has delete access, which it shares, it can be opened again only if the open shares delete access. An open that doesn't share delete access will fail with a sharing violation. It can be reopened with os.open() with the O_TEMPORARY flag, since this shares delete access. But Python's builtin open() does not share delete access, and neither do most other programs with which one might want to reopen the file. This behavior is limiting to the point of making NamedTemporaryFile() practically useless in Windows with delete=True. There is an ongoing discussion about redesigning NamedTemporaryFile() to never use O_TEMPORARY in Windows. ---------- nosy: +eryksun type: -> enhancement _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44055> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com