Question about the built-in file() and buffer size...

Jeff Epler jepler at unpythonic.net
Wed Feb 4 18:40:51 EST 2004


On Wed, Feb 04, 2004 at 03:14:23PM -0800, Darby Wong wrote:
> The documentation for file() says that the buffer size will be:
[...]

The buffer size argument is merely passed along to a call to setvbuf
as the "size" argument, like so:
	+setvbuf(0x0815e780, NULL, 0, 1024)               = 0
So it's beyond the control of Python.  Apparently your C library
disregards the actual size parameter given and choose another size
(perhaps related to the OS page size or the filesystem block size).

This behavior is different between 2.2.2 from redhat9 and python CVS.
In CVS, the buffer is allocated by Python:
	setvbuf(0x082089d0, 0x08183338, 0, 1024)         = 0
I don't know if 2.3 behaves like 2.2 or like this CVS release.  This
might give the behavior you're interested in, but it's still safer to
use .flush() at the right time, because either the C standard doesn't
guarantee much, or C libraries aren't very good.

Jeff




More information about the Python-list mailing list