Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5148

Re: py3k buffered IO - flush() required between read/write?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: py3k buffered IO - flush() required between read/write?
Date 2011-05-11 14:24 -0400
References <iqedg8$k5a$7@dont-email.me>
Newsgroups comp.lang.python
Message-ID <mailman.1422.1305138322.9059.python-list@python.org> (permalink)

Show all headers | View raw


On 5/11/2011 12:27 PM, Genstein wrote:

> In py3k is it necessary to flush() a file between read/write calls in order
> to see consistent results?
>
> I ask because I have a case under Python 3.2 (r32:88445) where it does
> appear to be, on both Gentoo Linux and Windows Vista.
>
> I've naturally read http://docs.python.org/py3k/library/io.html and
> http://docs.python.org/py3k/tutorial/inputoutput.html#reading-and-writing-files
> but could find no reference to such a requirement.
>
> PEP 3116 suggested this might not be required in py3k and the
> implementation notes in bufferedio.c state "BufferedReader,
> BufferedWriter and BufferedRandom...share a single buffer...this enables
> interleaved reads and writes without flushing." Which seemed conclusive
> but I'm seeing otherwise.
>
> I have a test case, which is sadly rather long:
> http://pastebin.com/xqrzKr5D It's lengthy because it's autogenerated
> from some rather more complex code I'm working on, in order to reproduce
> the issue in isolation.

I notice that you have required seek calls when switching between 
writing and reading. If you want others to look at this more, you should 
1) produce a minimal* example that demonstrates the questionable 
behavior, and 2) show the comparative outputs that raise your question. 
The code is way too long to cut and paste into an editor and see what is 
does on my windows machine.

*minimal = local minimum rather than global minimum. That means that 
removal or condensation of a line or lines removes the problem. In this 
case, remove extra seeks, unless doing so removes behavior discrepancy. 
Condense 1 byte writes to multibyte writes, unless ... . Are repeated 
interleavings required or is write, seek, read, seek, write enough?

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

py3k buffered IO - flush() required between read/write? Genstein <genstein@invalid.invalid> - 2011-05-11 17:27 +0100
  Re: py3k buffered IO - flush() required between read/write? Terry Reedy <tjreedy@udel.edu> - 2011-05-11 14:24 -0400
    Re: py3k buffered IO - flush() required between read/write? Genstein <genstein@invalid.invalid> - 2011-05-11 20:08 +0100
      Re: py3k buffered IO - flush() required between read/write? Terry Reedy <tjreedy@udel.edu> - 2011-05-11 17:38 -0400
        Re: py3k buffered IO - flush() required between read/write? Genstein <genstein@invalid.invalid> - 2011-05-12 14:30 +0100
          Re: py3k buffered IO - flush() required between read/write? Terry Reedy <tjreedy@udel.edu> - 2011-05-12 15:44 -0400
            Re: py3k buffered IO - flush() required between read/write? Genstein <genstein@invalid.invalid> - 2011-05-12 21:38 +0100
      Re: py3k buffered IO - flush() required between read/write? "Martin P. Hellwig" <martin.hellwig@gmail.com> - 2011-05-11 23:24 +0000

csiph-web