Python os.fsync() Method
Example
Force write file with file descriptor fd to disk:
#Import os Library
import os
#Open file
fd = os.open( "file.txt", os.O_RDWR|os.O_CREAT )
#Write a bytestring
str = b"test"
os.write(fd, str)
#Force write file to disc
os.fsync(fd)
#Close file
os.close(fd)
print "Closed file successfully!"
Run Code »
Definition and Usage
The os.fsync() method forces write of file
with file descriptor fd to disk.
Note: If you start with a file object, first do f.flush(),
then os.fsync(f.fileno()), to ensure that all
internal buffers related to f are written to the disk.
Note: Available on both WINDOWS and UNIX platforms.
Syntax
os.fsync(fd)
Parameter Values
| Parameter | Description |
|---|---|
| fd | Required. Specifies a file descriptor |
Technical Details
| Return Value: | None |
|---|---|
| Python Version: | 2.6 |