Issue12213
Created on 2011-05-30 02:52 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| io_interlaced_read_write.patch | vstinner, 2011-05-30 11:57 | review | ||
| bufrandom.patch | pitrou, 2011-08-19 18:33 | |||
| Messages (15) | |||
|---|---|---|---|
| msg137238 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2011-05-30 02:52 | |
The following code displays "Xbc" using io, and "bc" using _pyio (or an unbuffered file, e.g. io.FileIO):
-------------
import _pyio, io
with io.BytesIO(b'abc') as raw:
#with _pyio.BufferedRandom(raw) as f:
with io.BufferedRandom(raw) as f:
f.write(b"X")
print("pos?", f.tell(), raw.tell())
print(f.read())
-------------
I expect .write() to change the file position, and so "bc" must be the correct result, not "Wbc".
_pyio.BufferedRandom overrides its write method, whereas io.BufferedRandom doesn't.
I already noticed the implement difference of BufferedRandom.write(), but I don't remember if I reported it or not!?
|
|||
| msg137239 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2011-05-30 02:54 | |
> I already noticed the implement difference of BufferedRandom.write(), > but I don't remember if I reported it or not!? Yes, I already reported the difference: http://bugs.python.org/issue12062#msg135876 |
|||
| msg137259 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2011-05-30 11:57 | |
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(). |
|||
| msg137261 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2011-05-30 12:38 | |
See also issue #12215: TextIOWrapper has also issues on interlaced read-write. |
|||
| msg137690 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2011-06-05 11:25 | |
> My patch tries to fix interlaced read-write by always calling flush(), Why do you need to call flush()? Can't you read from the buffer? |
|||
| msg138736 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2011-06-20 16:01 | |
>> My patch tries to fix interlaced read-write by always calling flush(), > > Why do you need to call flush()? Can't you read from the buffer? Hum, my patch does not always call flush of the reader and the writer. On read, it flushs the writer. On write, it "flushes" the reader (undo readahead). It is maybe possible to do better (do something faster), but there should be some tricky cases with seek(). |
|||
| msg142479 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2011-08-19 17:10 | |
I think your expectations for BufferedRWPair are wrong. You should not use BufferedRWPair with the same underlying stream (that's the whole point of BufferedRWPair). |
|||
| msg142487 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2011-08-19 18:33 | |
Here is a patch. |
|||
| msg142528 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2011-08-20 12:54 | |
New changeset 5330af45f777 by Antoine Pitrou in branch '3.2': Issue #12213: Fix a buffering bug with interleaved reads and writes that http://hg.python.org/cpython/rev/5330af45f777 New changeset d7f6391954cf by Antoine Pitrou in branch 'default': Issue #12213: Fix a buffering bug with interleaved reads and writes that http://hg.python.org/cpython/rev/d7f6391954cf |
|||
| msg142529 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2011-08-20 12:55 | |
This should be fixed for BufferedRandom. As I said, I don't think BufferedRWPair is buggy. |
|||
| msg142530 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2011-08-20 13:16 | |
> You should not use BufferedRWPair with the same underlying stream (that's the whole point of BufferedRWPair). It might be documented. Something like "Warning: don't use the same stream as reader and writer, or the BufferedRWPair becomes inconsistent on interlaced read-write" ? |
|||
| msg142532 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2011-08-20 13:43 | |
New changeset cf2010e9f941 by Antoine Pitrou in branch '2.7': Issue #12213: Fix a buffering bug with interleaved reads and writes that http://hg.python.org/cpython/rev/cf2010e9f941 |
|||
| msg142545 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2011-08-20 17:56 | |
New changeset 524896c305ce by Antoine Pitrou in branch '3.2': Issue #12213: make it clear that BufferedRWPair shouldn't be called with the http://hg.python.org/cpython/rev/524896c305ce New changeset a423bd492d6c by Antoine Pitrou in branch 'default': Issue #12213: make it clear that BufferedRWPair shouldn't be called with the http://hg.python.org/cpython/rev/a423bd492d6c New changeset dd4f29e39756 by Antoine Pitrou in branch '2.7': Issue #12213: make it clear that BufferedRWPair shouldn't be called with the http://hg.python.org/cpython/rev/dd4f29e39756 |
|||
| msg142546 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2011-08-20 17:56 | |
I think it can be closed now. |
|||
| msg143476 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2011-09-04 06:41 | |
New changeset 8de8945ebfc3 by Antoine Pitrou in branch '3.2': Issue #12213: make it clear that BufferedRWPair shouldn't be called with the http://hg.python.org/cpython/rev/8de8945ebfc3 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:17 | admin | set | github: 56422 |
| 2011-09-04 06:41:30 | python-dev | set | messages: + msg143476 |
| 2011-08-20 17:56:47 | pitrou | set | status: open -> closed messages: + msg142546 |
| 2011-08-20 17:56:18 | python-dev | set | messages: + msg142545 |
| 2011-08-20 15:15:22 | pitrou | set | title: BufferedRandom, BufferedRWPair: issues with interlaced read-write -> BufferedRandom: issues with interlaced read-write |
| 2011-08-20 15:12:40 | Arfrever | set | title: BufferedRandom, BufferedRWPair: issues with interlaced read-write -> BufferedRandom, BufferedRWPair: issues with interlaced read-write |
| 2011-08-20 13:43:18 | python-dev | set | messages: + msg142532 |
| 2011-08-20 13:16:21 | vstinner | set | status: pending -> open messages:
+ msg142530 |
| 2011-08-20 12:55:08 | pitrou | set | status: open -> pending title: BufferedRandom, BufferedRWPair: issues with interlaced read-write -> BufferedRandom: issues with interlaced read-write messages: + msg142529 resolution: fixed |
| 2011-08-20 12:54:24 | python-dev | set | nosy:
+ python-dev messages: + msg142528 |
| 2011-08-19 18:33:25 | pitrou | set | files:
+ bufrandom.patch messages:
+ msg142487 |
| 2011-08-19 17:10:22 | pitrou | set | messages: + msg142479 |
| 2011-07-01 18:54:03 | pitrou | set | priority: normal -> critical type: behavior |
| 2011-07-01 16:50:53 | Arfrever | set | nosy:
+ Arfrever |
| 2011-06-20 16:47:43 | santoso.wijaya | set | nosy:
+ santoso.wijaya |
| 2011-06-20 16:01:05 | vstinner | set | messages: + msg138736 |
| 2011-06-05 11:25:41 | pitrou | set | messages: + msg137690 |
| 2011-05-30 13:08:27 | vstinner | set | versions: + Python 2.7, Python 3.2 |
| 2011-05-30 12:38:36 | vstinner | set | messages: + msg137261 |
| 2011-05-30 11:57:30 | vstinner | set | files:
+ io_interlaced_read_write.patch keywords: + patch messages: + msg137259 |
| 2011-05-30 11:30:46 | vstinner | set | title: BufferedRandom: write(); read() gives different result using io and _pyio -> BufferedRandom, BufferedRWPair: issues with interlaced read-write |
| 2011-05-30 03:20:08 | jcea | set | nosy:
+ jcea |
| 2011-05-30 02:54:51 | vstinner | set | messages: + msg137239 |
| 2011-05-30 02:52:58 | vstinner | set | components: + IO |
| 2011-05-30 02:52:39 | vstinner | create | |

