473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

knowing when file is flushed to disk

Hello,

I'm using a Python CGI script on a web server to log data from a remote site
every few minutes. I do not want to lose any data for whatever rare reason -
power outage/os crash just at the wrong moment etc. So I would like to know
when the data is actually written to disk and the file closed. At that point
I can signal deleting of the data at the remote site which has very limited
storage.

Is there some way from my Python script to know when the data is actually on
the disk. BTW server OS is Linux. Presumably calling flush() and close() on
the output file will initiate the disk write, but do they wait for the
actual disk write or immediately return leaving the OS to do the write when
it sees fit?

Any thoughts appreciated,

John
Aug 9 '06 #1
4 2116
John Pote wrote:
Is there some way from my Python script to know when the data is actually on
the disk. BTW server OS is Linux. Presumably calling flush() and close() on
the output file will initiate the disk write, but do they wait for the
actual disk write or immediately return leaving the OS to do the write when
it sees fit?
All you can do in Python (or similar) is call flush & close and hope
for the best :-)

There are many factors outwith the control of the language e.g.
* Library behaviour
* OS behaviour
* Hardware cache on the disk itself

That said, I've only found it an issue when a computer is under heavy
load.

Hope this helps,
Davy Mitchell

http://www.latedecember.com/sites/personal/davy/

Aug 9 '06 #2
John Pote:
Is there some way from my Python script to know when the data is actually on
the disk. BTW server OS is Linux. Presumably calling flush() and close() on
the output file will initiate the disk write, but do they wait for the
actual disk write or immediately return leaving the OS to do the write when
it sees fit?
No, commonly they will schedule these operations and return quickly.
You can try os.fsync but there are no real guarantees about what that
does either. There's an amusing message from Tim Peters about this:
http://mail.zope.org/pipermail/zodb-...ly/007689.html

Neil
Aug 10 '06 #3
Thanks for the replies. I guessed the situation would be flush() and trust.
The probability of a crash between flush() returning and data actually
written resulting in a trashed disk must be very small. But if you can be
certain without too much effort it's got to be a good idea, so I thought I'd
ask anyway.

How does the banking industry handle this sort of thing? Could be big bucks
if something goes wrong for them!

Thanks again,

John
Aug 10 '06 #4
On Wed, 09 Aug 2006 16:13:19 +0000 (GMT)
John Pote <jo******@blueyonder.co.ukwrote:

#Is there some way from my Python script to know when the data is actually on
#the disk. BTW server OS is Linux. Presumably calling flush() and close() on
#the output file will initiate the disk write, but do they wait for the
#actual disk write or immediately return leaving the OS to do the write when
#it sees fit?

You may want to look into sqlite -- it is a single-file based SQL
database which is known to be extremely robust in face of problems you
describe. One of its design goals was to provide a replacement for
file storage. There is python binding http://pysqlite.org which is,
IIRC, supposed to be in stdlib for Python 2.5

That said, if your disk and/or OS is lying about the fact whether it
has actually wrote the data or not, there is not much you can do.

--
Best wishes,
Slawomir Nowaczyk
( Sl***************@cs.lth.se )

If vegetarians love animals so much, why do they eat all their food???

Aug 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Lu | last post by:
Hi there, I got a program to write data to a randomly accessed file (the program moves file pointer to a certain position of the file according the current "keyword" and then writes data). It...
9
by: Jon LaBadie | last post by:
Suppose I'm using stdio calls to write to a disk file. One possible error condition is no space on file system or even (in unix environment) a ulimit of 0 bytes. Which calls would be expected to...
14
by: Mark Broadbent | last post by:
Does anybody know what is (factual please -not just guess) the quickest method to read data from a file? I am not interested in the format of the data (i.e. blocks, bytes, string etc) just that the...
2
by: Leonardo Francalanci | last post by:
I was reading "Don't be lazy, be consistent: Postgres-R, a new way to implement Database Replication" and I found this: "5.1 General configuration PostgreSQL uses a force strategy to avoid redo...
4
by: Doug | last post by:
Hi, It looks like the only way to get a size of a file within csharp is to use FileInfo and the Length property. However that only returns the number of bytes in the file which is translating...
6
by: Steven D'Aprano | last post by:
Closing a file can (I believe) raise an exception. Is that documented anywhere? I've spent a lot of frustrating time trying to track this down, with no luck, which suggests that either my...
3
by: Rahul Babbar | last post by:
Hi All, When could be the possible reasons that could make a database inconsistent? I was told by somebody that it could become inconsistent if you " force all the applications to a close on...
3
by: Stef Mientki | last post by:
hello, I've a program (not written in Python) that generates a few thousands bytes per second, these files are dumped in 2 buffers (files), at in interval time of 50 msec, the files can be read...
4
by: DR | last post by:
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.