Python-os-fdatasync
提供:Dev Guides
Python os.fdatasync()メソッド
説明
Pythonメソッド* fdatasync()*は、ファイル記述子_fd_を使用してファイルをディスクに強制的に書き込みます。 これはメタデータの更新を強制しません。 バッファをフラッシュする場合は、このメソッドを使用できます。
構文
以下は* fdatasync()*メソッドの構文です-
os.fdatasync(fd);
パラメーター
- fd -これは、データが書き込まれるファイル記述子です。
戻り値
このメソッドは値を返しません。
例
次の例は、fdatasync()メソッドの使用方法を示しています-
#!/usr/bin/python
import os, sys
# Open a file
fd = os.open( "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.
os.fdatasync(fd)
# Now read this file from the beginning.
os.lseek(fd, 0, 0)
str = os.read(fd, 100)
print "Read String is : ", str
# Close opened file
os.close( fd )
print "Closed the file successfully!!"
上記のプログラムを実行すると、次の結果が生成されます-
Read String is : This is test
Closed the file successfully!!