Python Glossary Русский

all Python 3osfunction

os.fsync

os — synchronization

Flush a file descriptor's buffers to disk.

Syntax

os.fsync(...)

It flushes OS buffers to disk, but not Python's: call f.flush() first, then os.fsync(f.fileno()). That is not enough for durable file creation — the new name lives in the directory, and on Linux the directory's descriptor needs fsync too. The call is expensive, milliseconds on slow disks, so it is not issued after every small write.

Examples

import os
fd = os.open('fsync_demo.txt', os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
os.write(fd, b'x')
print(os.fsync(fd) is None)   # → True
os.close(fd)
os.remove('fsync_demo.txt')

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy