Python Glossary Русский

all Python 3Linuxosfunction

os.fdatasync

os — synchronization

Like fsync, but flushes only data, not all metadata. Availability: Unix.

Syntax

os.fdatasync(...)

It is faster than fsync because it does not wait for metadata unneeded for reading the data back, such as modification time. The file size is still persisted. It is missing on macOS; portable code uses fsync, and where fdatasync is wanted for speed, check hasattr(os, 'fdatasync').

Examples

import os
fd = os.open('data.log', os.O_WRONLY | os.O_CREAT)   # → ? дескриптор открытого файла, например 3
print(os.write(fd, b'payload\n'))   # → 8
os.fdatasync(fd)   # → ? только Unix: None; данные гарантированно на диске, метаданные вроде времени изменения могут остаться в кеше
os.fsync(fd)   # → ? None; в отличие от fdatasync сбрасывает и метаданные — надёжнее, но дороже
os.fdatasync(999)   # → OSError: [Errno 9] Bad file descriptor — 999 не открытый дескриптор

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy