Avoiding excessive writes

John Machin sjmachin at lexicon.net
Thu Mar 19 06:14:16 CET 2009

On Mar 19, 1:20 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> En Thu, 19 Mar 2009 00:52:54 -0200, <prometheus... at gmail.com> escribió:
> > I'm aware that C, and thus Python I suppose, will cache file writes
> > for efficiency and to avoid excessive disk activity,
> Python 2.X, yes, because it uses C file streams (FILE) to implement Python  
> file objects. Python 3.x avoids that layer.
> > Does the cache get written simply when an X-byte buffer fills up, and
> > can I change X?
> Yes, use the bufsize argument to open.
> > Does it write after waiting so long?
> I don't think so. You may call flush() yourself after some time.

After it leaves Python, and the C stdio if that's used, isn't it then
at the whim of the operating system exactly when and how much gets
written to disk? My understanding is that this layer sometimes makes
an effort to detect that the client is writing size X blocks
sequentially and may decide to to buffer them up and do an N*X
physical write later (like where N * X might represent a whole number
of tracks) ... and/or you've got the drive itself which may do some
buffering ...

More information about the Python-list mailing list