Thursday, December 11, 2025
HomeLanguagesPython | os.fdatasync() method

Python | os.fdatasync() method

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.fdatasync() method in Python is used to force write of the file associated with the given file descriptor. Unlike os.fsync() method, it does not force update of metadata.
os.fdatasync() method is faster than os.fsync() method because it needs to force only one disk write instead of two.

Syntax: os.fdatasync(fd)

Parameter:
fd: A file descriptor for which data is to be written.

Return type: This method does not return any value.

Code: Use of os.fdatasync() method




# Python program to explain os.fdatasync() method 
    
# importing os module 
import os
  
  
# File path
path = 'file.txt'
  
# Open the file and get
# the file descriptor 
# associated with 
# using os.open() method
fd = os.open(path, os.O_RDWR)
  
  
# Write a bytestring
str = b"neveropen" 
  
os.write(fd, str)
  
  
# The written string is
# available in program buffer
# but it might not actually 
# written to disk until
# program is closed or 
# file descriptor is closed. 
  
# sync. all internal buffers
# associated with the file descriptor
# with disk (force write of file)
# using os.fdatasync() method
os.fdatasync(fd)
print("Force write of file committed successfully")
  
# Close the file descriptor 
os.close(fd)
  
# os.fdatasync() method
# does not force update of
# metadata. if you want to 
# update it too, use
# os.fsync() method instead. 


Output:

Force write of file committed successfully

Reference: https://docs.python.org/3/library/os.html#os.fdatasync

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32440 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6811 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12023 POSTS0 COMMENTS
Shaida Kate Naidoo
6943 POSTS0 COMMENTS
Ted Musemwa
7193 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS