Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(479)

Issue 12470: [issue4428] make io.BufferedWriter observe max_buffer_size limits

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 3 months ago by gregory.p.smith
Modified:
15 years, 2 months ago
Reviewers:
Antoine Pitrou
Base URL:
http://svn.python.org/view/*checkout*/python/branches/py3k/
Visibility:
Public.

Description

http://bugs.python.org/issue4428 - patch gps04.

Patch Set 1 #

Total comments: 10

Patch Set 2 : updated, many more test cases. now handles buffering on array.arrays properly. #

Total comments: 8
Unified diffs Side-by-side diffs Delta from patch set Stats (+238 lines, -10 lines) Patch
Lib/io.py View 1 2 chunks +75 lines, -7 lines 4 comments Download
Lib/test/test_io.py View 1 2 chunks +163 lines, -3 lines 4 comments Download

Messages

Total messages: 6
Antoine Pitrou
http://codereview.appspot.com/12470/diff/1/2 File Lib/io.py (right): http://codereview.appspot.com/12470/diff/1/2#newcode1055 Line 1055: # b is an iterable of ints, it ...
15 years, 3 months ago (2009-01-20 11:12:46 UTC) #1
gregory.p.smith
Just responding to your comments on the support for generators and non buffer api supporting ...
15 years, 3 months ago (2009-01-20 22:44:37 UTC) #2
Antoine Pitrou
Hi! > Agreed. But since I want to merge this into release30-maint doing that sounds ...
15 years, 3 months ago (2009-01-20 23:27:47 UTC) #3
gregory.p.smith
updated, many more test cases. now handles buffering on array.arrays properly.
15 years, 2 months ago (2009-02-01 06:27:43 UTC) #4
gregory.p.smith
updated in the -gps05 patch. http://codereview.appspot.com/12470/diff/1/2 File Lib/io.py (right): http://codereview.appspot.com/12470/diff/1/2#newcode1066 Line 1066: while chunk and ...
15 years, 2 months ago (2009-02-01 06:28:03 UTC) #5
Antoine Pitrou
15 years, 2 months ago (2009-02-12 21:30:44 UTC) #6
In general I think the patch is quite complicated for what it tries to solve. In
particular I think the memoryview itemsize issue makes things trickier than they
should be. It would be nice if memoryview could support changing the internal
format, and for the most common case of switching to bytes ('B') it would be
easy to implement.

http://codereview.appspot.com/12470/diff/401/601
File Lib/io.py (right):

http://codereview.appspot.com/12470/diff/401/601#newcode1080
Line 1080: data = memoryview(data.tostring())
memoryview doesn't have a tostring() method (it's called tobytes()).

http://codereview.appspot.com/12470/diff/401/601#newcode1099
Line 1099: remaining_bytes = (len(data)-items_written)*item_size
I think you must first update `items_written` by taking  `e.characters_written`
into account.

(and the problem is that `e.characters_written` is not necessarily a multiple of
`item_size`!... which makes me think that the memoryview approach, while
algorithmically elegant, might not be a good choice here :-))

http://codereview.appspot.com/12470/diff/401/601#newcode1108
Line 1108: written += e.characters_written - before
You could first try to stuff as much data as possible in `self._write_buf`.

http://codereview.appspot.com/12470/diff/401/601#newcode1127
Line 1127: if len(self._write_buf) > self.max_buffer_size:
Can it still happen? It seems you are taking all precautions to avoid it.

http://codereview.appspot.com/12470/diff/401/602
File Lib/test/test_io.py (right):

http://codereview.appspot.com/12470/diff/401/602#newcode535
Line 535: max_buffer_size=1)
What about buffer_size=0? Should it also raise?

http://codereview.appspot.com/12470/diff/401/602#newcode559
Line 559: self.assertEquals(first_two_writes, writer._write_stack[:2])
This is very much implementation-dependent (for instance another implementation
could write in buffer-sized chunks), it would be better IMHO to just
b''.join(writer._write_stack) and compare the outcome.

http://codereview.appspot.com/12470/diff/401/602#newcode618
Line 618: bufio.write(b"ijklm")  # rejected, already full
Not sure I understand why it should raise. 15 bytes is smaller than the
max_buffer_size.

http://codereview.appspot.com/12470/diff/401/602#newcode648
Line 648: self.assertEquals(0, e.characters_written)
Here I would have expected the data to be buffered (2 bytes have been written
before blocking, then the remaining data is 15 bytes which is smaller than
max_buffer_size).
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b