Richard Oudkerk <shibt...@gmail.com> added the comment:

I wrote in an earlier message that a file opened with O_TEMPORARY must be 
reopened with O_TEMPORARY.  This is not quite accurate.

Using O_TEMPORARY causes the FILE_SHARE_DELETE sharing mode to be used, and a 
file currently opened with FILE_SHARE_DELETE can only be reopened with 
FILE_SHARE_DELETE.

Unfortunately using O_TEMPORARY is the only way allowed by msvcrt to get 
FILE_SHARE_DELETE, even though it also has the orthogonal effect of unlinking 
the file when all handles are closed.

The nice thing about FILE_SHARE_DELETE is that it gives Unix-like behaviour: 
the file can be renamed or deleted while you have an open handle, and you can 
still continue to use the handle.

Attached is a mostly untested attempt at writing replacements for open() and 
os.open() which use the FILE_SHARE_DELETE sharing mode.  Among other things, 
these can be used for reopening temporary files.

Even if tempfile does not use make use of this, I think something similar would 
be useful in the stdlib.

----------
Added file: http://bugs.python.org/file26229/share.py

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

Reply via email to