<br><br><div class="gmail_quote">On Sun, Mar 13, 2011 at 3:15 AM, Tim Allen <span dir="ltr"><<a href="mailto:screwtape@froup.com">screwtape@froup.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Sat, Mar 12, 2011 at 02:33:45PM +0200, Pandelis Theodosiou wrote:<br>
> On Sat, Mar 12, 2011 at 3:32 AM, Tim Allen <<a href="mailto:screwtape@froup.com">screwtape@froup.com</a>> wrote:<br>
</div><div class="im">> > Of course, if you flush after every disk read, your program will run<br>
> > a bit more slowly and with more I/O... for an application where<br>
> > reliability is more important than performance (like logging) that's<br>
> > probably acceptable.<br>
><br>
> You may also setup a timer that flushes files every, say, 5 minutes.<br>
><br>
> One other thing I've read in the Python.org site is that flush() is not 100%<br>
> sure to work immediately and should be used in combination with os.fsync().<br>
> Is there someone that can explain if that is correct?<br>
<br>
</div>Depends what you mean by 'work'. The standard library (Python's or C's)<br>
buffers reads and writes because calling into the kernel is expensive.<br>
The kernel buffers reads and writes because disk I/O is even more<br>
expensive. flush() tells the standard library "send buffered data to the<br>
kernel right now" which means your data should survive if your process<br>
crashes. fsync() tells the kernel "send buffered data to the disk right<br>
now", which means your data should survive if the entire machine<br>
crashes.<br>
<br>
Whether you call nothing, just flush(), or both flush() and fsync()<br>
depends on how your software balances performance versus reliability.<br>
<div><div></div><div class="h5"><br>
<br></div></div></blockquote><div><br>thnx, very clear explanation. <br></div></div><style type="text/css">#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}</style><style>
qtl {
        position: absolute;
        border: 1px solid #cccccc;
        -moz-border-radius: 5px;
        opacity: 0.2;
        line-height: 100%;
        z-index: 999;
        direction: ltr;
}
qtl:hover,qtl.open {
        opacity: 1;
}
qtl,qtlbar {
        height: 22px;
}
qtlbar {
        display: block;
        width: 100%;
        background-color: #cccccc;
        cursor: move;
}
qtlbar img {
        border: 0;
        padding: 3px;
        height: 16px;
        width: 16px;
        cursor: pointer;
}
qtlbar img:hover {
        background-color: #aaaaff;
}
qtl>iframe {
        border: 0;
        height: 0;
        width: 0;
}
qtl.open {
        height: auto;        
}
qtl.open>iframe {
        height: 200px;
        width: 300px;
}
</style><div style="visibility: hidden; display: inline;" id="avg_ls_inline_popup"></div><style type="text/css">#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}</style>
        <img src="http://www.qtl.co.il/img/copy.png" title="Copy Selction"><a href="http://int.ask.com/web?siteid=10000861&webqsrc=999&l=dis&q=_______________________________________________" title="Search With Ask" target="_blank"><img src="http://www.ask.com/favicon.ico"></a><img src="http://translate.google.com/favicon.ico" title="Translate With Google">