Richard Oudkerk <[email protected]> added the comment:
> Agreed. Richard: do you have time to put something together?
> I'm happy to try if you don't.
I'm looking into it.
Unfortunately, it seems that you need to use non-default flags when reopening a
shared file. Eg, if the file is currently opened with SH_DENYNO and
O_TEMPORARY, then you must reopen it using SH_DENYNO and O_TEMPORARY.
However, I have an initial implementation of os.sopen() which makes the
following work:
import os, tempfile
FNAME = "foo.txt"
DATA = "hello bob"
def opener(name, flag, mode=0o777):
return os.sopen(name, flag | os.O_TEMPORARY, os.SH_DENYNO, mode)
with open(FNAME, "w", opener=opener) as f:
f.write(DATA)
f.flush()
with open(FNAME, "r", opener=opener) as f:
assert f.read() == DATA
assert not os.path.exists(FNAME)
BTW, Maybe it would be better to add a keyword-only shareflag argument to
os.open() rather than add os.sopen().
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue14243>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com