Python os.fdatasync() Method
Python OS File/Directory Methods
Overview
The os.fdatasync() method is used to force the file specified by the file descriptor fd to be written to disk, but does not force the file's status information to be updated. If you need to flush the buffer, you can use this method.
Available on Unix.
Syntax
fdatasync()The method syntax format is as follows:
os.fdatasync(fd);
Parameters
fd-- file descriptor
Return Value
This method has no return value.
Example
The following example demonstrates the use of the fdatasync() method:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 "/tmp/foo.txt" fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 写入字符串 os.write(fd, "This is test") # 使用 fdatasync() 方法 os.fdatasync(fd) # 读取文件 os.lseek(fd, 0, 0) str = os.read(fd, 100) print "读取的字符是 : ", str # 关闭文件 os.close( fd ) print "关闭文件成功!!"
The output of executing the above program is:
读取的字符是 : This is test 关闭文件成功!!Other Extensions