Python Glossary Русский

Python 3.3+Linux · macOSosfunction

os.sync

os — synchronization

Flush all filesystem buffers to disk. Availability: Unix.

Syntax

os.sync(...)

It flushes buffers of every filesystem at once rather than one file, which makes it slow and indiscriminate. For your own data fsync on the specific file is right. It is mostly useful before unplugging media or in system utilities.

Examples

import os
os.sync()   # → None — буферы всех смонтированных файловых систем сброшены на диск
fd = os.open('report.txt', os.O_WRONLY | os.O_CREAT)   # → ? дескриптор открытого файла, например 3
print(os.write(fd, b'done\n'))   # → 5
os.sync()   # → ? только Unix: записанная строка теперь точно на диске — так страхуются перед перезагрузкой или снятием питания
os.fsync(fd)   # → ? None; сбрасывает только этот файл — точечнее и дешевле, чем синхронизация всей системы

See also

Open in the full glossarydocs.python.orgReport an inaccuracy