You are here : python_2ososfdatasync

os.fdatasync() - os


The method fdatasync() forces write of file with filedescriptor fd to disk. This does not force update of metadata. If you want to flush your buffer then you can use this method.

  • fd -- This is the file descriptor for which data to be written.





import os, sys

# Open a file
fd = "foo.txt", os.O_RDWR|os.O_CREAT )

# Write one string
os.write(fd, "This is test")

# Now you can use fdatasync() method.
# Infact here you would not be able to see its effect.

# Now read this file from the beginning.
os.lseek(fd, 0, 0)
str =, 100)
print "Read String is : ", str

# Close opened file
os.close( fd )

print "Closed the file successfully!!"

Output / Return Value

When we run above program, it produces following result:

Read String is : This is test Closed the file successfully!!


Alternatives / See Also