s-m-e
s-m-e

Reputation: 3729

Flush data written to numeric file handle?

How can I flush the content written to a file opened as a numeric file handle?

For illustration, one can do the following in Python:

f = open(fn, 'w')
f.write('Something')
f.flush()

On the contrary, I am missing a method when doing the following:

import os
fd = os.open(fn)
os.pwrite(fd, buffer, offset)
# How do I flush fd here?

Upvotes: 0

Views: 142

Answers (1)

zxxc
zxxc

Reputation: 355

Use os.fsync(fd). See docs for fsync.

Be careful if you do fsync on a file descriptor obtained from a python file object. In that case you need to flush the python file object first.

Upvotes: 2

Related Questions