[issue12213] BufferedRandom, BufferedRWPair: issues with interlaced read-write

STINNER Victor report at bugs.python.org
Mon May 30 13:57:31 CEST 2011


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

io_interlaced_read_write.patch:
 - add interlaced read/write tests for BufferedRandom and BufferedRWPair
 - _pyio: move "undo readahead" code into BufferedReader.flush()
 - io: BufferedRandom.flush() doesn't undo readahead if the write buffer is empty, so it's possible to call it in read methods without flusing the readahead buffer when it's not needed
 - read(), read1(), readinto(), peek() calls writer.flush()
 - write() calls reader.flush() (undo readahead)

TODO:
 - tests BufferedRWPair with read-only + write-only files because I'm not sure if my tests using readable and writeable methods
 - _pyio: undo the readahead in BufferedReader.flush() is no perfect, because BufferedReader is supposed to be read-only. I choosed that to factorize the code between BufferedRandom and BufferedRWPair
 - what happens if a write occurs during _pyio.BufferedReader.flush()? "if self._read_buf: <write occurs> with self._read_lock: ...". We may protect the read of self._read_buf with the read lock.

My patch tries to fix interlaced read-write by always calling flush(), but I am not sure that it doesn't change read-only and write-only cases. There are maybe some unnecessary call to flush().

----------
keywords: +patch
Added file: http://bugs.python.org/file22190/io_interlaced_read_write.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12213>
_______________________________________


More information about the Python-bugs-list mailing list