python-atomicwrites
python-atomicwrites copied to clipboard
Use Linux' O_TMPFILE for tmpfiles
https://github.com/untitaker/rust-atomicwrites/issues/2
Unsure how to call linkat
in Python.
https://docs.python.org/3/library/os.html#os.O_TMPFILE
Something like this seems to work since Python 3.4:
import os
fd = os.open('.', os.O_TMPFILE | os.O_RDWR)
path = '/proc/self/fd/{0}'.format(fd)
os.link(path, 'spam', src_dir_fd=0, follow_symlinks=True)
@jwilk That doesn't seem particularly performant or elegant though. It seems that there is a package on PyPI that provides bindings for this call, however, that would be quite a microdependency.
AFAICT NamedTemporaryFile already sets this flag
I think you meant (unnamed) TemporaryFile
, which indeed tries to use O_TMPFILE
since Python 3.5:
https://bugs.python.org/issue21515