
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2014-12-22 11:41 bymartin.panter, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| bytesio_exported_reject_close.patch | serhiy.storchaka,2014-12-23 07:26 | review | ||
| bytesio_exported_reject_close.v2.patch | martin.panter,2015-01-06 07:01 | review | ||
| bytesio_exported_reject_close.v3.patch | serhiy.storchaka,2015-01-31 13:12 | review | ||
| bytesio_exported_reject_close.v4.patch | martin.panter,2015-02-02 03:24 | review | ||
| Messages (12) | |||
|---|---|---|---|
| msg233016 -(view) | Author: Martin Panter (martin.panter)*![]() | Date: 2014-12-22 11:41 | |
IOBase.close() doc says file operations raise ValueError, but it is not obvious to me that reading back the “file” buffer is a file operation.>>> with BytesIO() as b:... b.write(b"123")... 3>>> b.getvalue()Traceback (most recent call last): File "<stdin>", line 1, in <module>ValueError: I/O operation on closed file.Even worse, the memoryview gets corrupted on close():>>> b = BytesIO(b"123")>>> m = b.getbuffer()>>> b.close()>>> bytes(m)b'\x98\x02>'I also noticed that in the “io” implementation, writing to the file seems to be completely disallowed, even if it would not seem to change the size:>>> b = BytesIO(b"123")>>> m = b.getbuffer()>>> b.write(b"x")Traceback (most recent call last): File "<stdin>", line 1, in <module>BufferError: Existing exports of data: object cannot be re-sized | |||
| msg233018 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2014-12-22 12:29 | |
getvalue() doesn't work after close() for purpose. close() frees memory used by BytesIO.>>> import io, sys>>> bio = io.BytesIO()>>> sys.getsizeof(bio)52>>> bio.write(b'x'*1000)1000>>> sys.getsizeof(bio)1053>>> bio.close()>>> sys.getsizeof(bio)52Changing the behavior will cause regression.The behavior of memoryview looks as a bug. | |||
| msg233023 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2014-12-22 19:46 | |
> Even worse, the memoryview gets corrupted on close():The BytesIO object should probably reject closing when a buffer is exported.> writing to the file seems to be completely disallowed, even if it > would not seem to change the size:An enhancement is probably possible there. | |||
| msg233036 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2014-12-23 07:26 | |
Here is a patch which rejects close() when a buffer is exported. | |||
| msg233506 -(view) | Author: Martin Panter (martin.panter)*![]() | Date: 2015-01-06 07:01 | |
Updated patch, to also document the BytesIO buffer is no longer available when closed. The StringIO documentation actually already says this, but I rarely use StringIO. :) | |||
| msg235108 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2015-01-31 13:12 | |
Why not just copy the StringIO documentation? | |||
| msg235138 -(view) | Author: Martin Panter (martin.panter)*![]() | Date: 2015-02-01 00:57 | |
I can live with the wording of StringIO, but personally prefer my v2 patch. I now understand that calling close() for Bytes and StringIO objects is intended to immediately free the memory buffer holding the file data (like deleting a file in Windows). So I think it would be better to document this as a property of the whole object, rather than a special exception for each of the getbuffer(), getvalue() non-file-API methods.I’m happy to propose a similar wording for the StringIO class if you want to make them consistent. | |||
| msg235159 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2015-02-01 10:53 | |
Yes, it would be good to make the documentation of BytesIO and StringIO consistent. | |||
| msg235222 -(view) | Author: Martin Panter (martin.panter)*![]() | Date: 2015-02-02 03:24 | |
Here is an option that moves the documentation for discarding the buffer into the class description for both BytesIO and StringIO; what do you think? I would be happy enough with any of the last three patches, so I don’t want to hold this up forever :) | |||
| msg235229 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2015-02-02 07:32 | |
LGTM. | |||
| msg235304 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2015-02-03 00:05 | |
New changesete62d54128bd3 by Serhiy Storchaka in branch '3.4':Issue#23099: Closing io.BytesIO with exported buffer is rejected now tohttps://hg.python.org/cpython/rev/e62d54128bd3 | |||
| msg235317 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2015-02-03 07:31 | |
New changesetb9d4c013b09a by Serhiy Storchaka in branch 'default':Issue#23099: Closing io.BytesIO with exported buffer is rejected now tohttps://hg.python.org/cpython/rev/b9d4c013b09a | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:11 | admin | set | github: 67288 |
| 2015-02-03 07:40:55 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2015-02-03 07:31:49 | python-dev | set | messages: +msg235317 |
| 2015-02-03 00:05:21 | python-dev | set | nosy: +python-dev messages: +msg235304 |
| 2015-02-02 07:32:50 | serhiy.storchaka | set | assignee:serhiy.storchaka messages: +msg235229 |
| 2015-02-02 03:24:33 | martin.panter | set | files: +bytesio_exported_reject_close.v4.patch messages: +msg235222 |
| 2015-02-01 10:53:05 | serhiy.storchaka | set | messages: +msg235159 |
| 2015-02-01 00:57:25 | martin.panter | set | messages: +msg235138 |
| 2015-01-31 13:12:03 | serhiy.storchaka | set | files: +bytesio_exported_reject_close.v3.patch messages: +msg235108 |
| 2015-01-06 07:01:24 | martin.panter | set | files: +bytesio_exported_reject_close.v2.patch messages: +msg233506 |
| 2014-12-23 07:26:17 | serhiy.storchaka | set | files: +bytesio_exported_reject_close.patch versions: + Python 2.7, Python 3.5 messages: +msg233036 keywords: +patch stage: patch review |
| 2014-12-22 19:46:49 | pitrou | set | nosy: +pitrou messages: +msg233023 |
| 2014-12-22 12:29:01 | serhiy.storchaka | set | nosy: +serhiy.storchaka messages: +msg233018 |
| 2014-12-22 11:41:17 | martin.panter | create | |