os.fsync() is used in Python to force the file associated with a given file descriptor to be written.
In case we are working with a file object (say f) and not a file descriptor, then we need to use f.flush () and then os.fsync (f.fileno ()), to ensure that all buffers associated with the F file object are written to disk.
Syntax: os.fsync (fd)
fd: A file descriptor for which buffer sync is required.
Return type: This method does not return any value.
Code # 1: Using the method
os.fsync () b >
Force write of file committed successfully