[New-bugs-announce] [issue12062] Buffered I/O inconsistent with unbuffered I/O in certain cases
report at bugs.python.org
Thu May 12 15:07:28 CEST 2011
New submission from Genstein <pythondev at genstein.net>:
Reporting this as requested by Antoine Pitrou: Under certain circumstances in Python 3.2 (r32:88445) it's possible for buffered I/O to lose data before it is written and/or return the wrong results when reading. I tripped over this issue whilst writing an assembler which first writes out a bunch of binary data and then goes back over it in a somewhat arbitrary order patching addresses.
The following code demonstrates the issue:
START = 0
MID = 1
LENGTH = 4
f = open("test.bin", "w+b", buffering = buffering)
for i in range(LENGTH):
print("Buffered result: ")
Output on both Gentoo and Vista is:
Expected output is b'\x01' in both cases.
The issue is reproducible with larger files provided that the constants are increased ~proportionally (START 0, MID 500, LENGTH 1000 for example). Transposing the buffered/unbuffered tests and/or using different buffer sizes for the buffered test seem have no effect.
The lengthy code at this URL also demonstrates the issue: http://pastebin.com/xqrzKr5D The above was produced from this code, which was autogenerated by intercepting my assembler's output.
title: Buffered I/O inconsistent with unbuffered I/O in certain cases
versions: Python 3.2
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce