<br><br><div class="gmail_quote">On Sun, Mar 13, 2011 at 3:15 AM, Tim Allen <span dir="ltr">&lt;<a href="mailto:screwtape@froup.com">screwtape@froup.com</a>&gt;</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>
&gt; On Sat, Mar 12, 2011 at 3:32 AM, Tim Allen &lt;<a href="mailto:screwtape@froup.com">screwtape@froup.com</a>&gt; wrote:<br>
</div><div class="im">&gt; &gt; Of course, if you flush after every disk read, your program will run<br>
&gt; &gt; a bit more slowly and with more I/O... for an application where<br>
&gt; &gt; reliability is more important than performance (like logging) that&#39;s<br>
&gt; &gt; probably acceptable.<br>
&gt;<br>
&gt; You may also setup a timer that flushes files every, say, 5 minutes.<br>
&gt;<br>
&gt; One other thing I&#39;ve read in the Python.org site is that flush() is not 100%<br>
&gt; sure to work immediately and should be used in combination with os.fsync().<br>
&gt; Is there someone that can explain if that is correct?<br>
<br>
</div>Depends what you mean by &#39;work&#39;. The standard library (Python&#39;s or C&#39;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 &quot;send buffered data to the<br>
kernel right now&quot; which means your data should survive if your process<br>
crashes. fsync() tells the kernel &quot;send buffered data to the disk right<br>
now&quot;, 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&amp;webqsrc=999&amp;l=dis&amp;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">