classification
Title: Ignored exceptions in test_memoryio
Type: behavior Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, pitrou, vstinner
Priority: normal Keywords: patch

Created on 2019-05-26 14:54 by pitrou, last changed 2019-05-28 00:19 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13601 merged vstinner, 2019-05-27 23:07
PR 13604 merged miss-islington, 2019-05-27 23:44
Messages (7)
msg343552 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2019-05-26 14:54
I see the following kind of exceptions when running test_memoryio:

Exception ignored in: <function IOBase.__del__ at 0x7f7cd44f49b0>
Traceback (most recent call last):
  File "/home/antoine/cpython/default/Lib/_pyio.py", line 409, in __del__
    self.close()
  File "/home/antoine/cpython/default/Lib/_pyio.py", line 2152, in close
    if self.buffer is not None and not self.closed:
  File "/home/antoine/cpython/default/Lib/_pyio.py", line 2093, in buffer
    return self._buffer
AttributeError: 'StringIO' object has no attribute '_buffer'
Exception ignored in: <function IOBase.__del__ at 0x7f7cd44f49b0>
Traceback (most recent call last):
  File "/home/antoine/cpython/default/Lib/_pyio.py", line 409, in __del__
    self.close()
  File "/home/antoine/cpython/default/Lib/_pyio.py", line 2152, in close
    if self.buffer is not None and not self.closed:
  File "/home/antoine/cpython/default/Lib/_pyio.py", line 2093, in buffer
    return self._buffer
AttributeError: 'StringIO' object has no attribute '_buffer'
ok

It seems this could be related to issue18748.
msg343652 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-27 16:02
Multiple tests log an "Exception ignored", but all of them come from the Python implementation.

The problem is that _pyio.BytesIO and _pyio.TextIOWrapper initialize their self._buffer and self._seekable attribute "later" in the constructor, but then expect these attribute to exist in __del__().

Example:

>>> import _pyio; _pyio.BytesIO(b'data', foo=b'fat')

Exception ignored in: <function IOBase.__del__ at 0x7f1874c5c550>
Traceback (most recent call last):
  File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 409, in __del__
    self.close()
  File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 903, in close
    self._buffer.clear()
AttributeError: 'BytesIO' object has no attribute '_buffer'

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'foo'

BytesIO.__init__() is not even called.

An easy fix would be to do nothing in __del__() if hasattr(self, '_buffer') if false.
msg343653 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2019-05-27 16:04
Or to add `_buffer = None` at the class level.
msg343700 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-27 23:08
Antoine:
> Or to add `_buffer = None` at the class level.

Ok, I wrote bpo-13601 to implement this idea and fix test_memoryio warnings.
msg343709 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-27 23:44
New changeset a3568417c49f36860393075b21c93996a5f6799b by Victor Stinner in branch 'master':
bpo-37054, _pyio: Fix BytesIO and TextIOWrapper __del__() (GH-13601)
https://github.com/python/cpython/commit/a3568417c49f36860393075b21c93996a5f6799b
msg343718 - (view) Author: miss-islington (miss-islington) Date: 2019-05-28 00:05
New changeset 0f352d44e7c14c1c93e3999402c85512b9d5a6ca by Miss Islington (bot) in branch '3.7':
bpo-37054, _pyio: Fix BytesIO and TextIOWrapper __del__() (GH-13601)
https://github.com/python/cpython/commit/0f352d44e7c14c1c93e3999402c85512b9d5a6ca
msg343720 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-28 00:19
Thanks for the report Antoine. It is now fixed in 3.7 and master branches.
History
Date User Action Args
2019-05-28 00:19:06vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg343720

stage: patch review -> resolved
2019-05-28 00:05:55miss-islingtonsetnosy: + miss-islington
messages: + msg343718
2019-05-27 23:44:31miss-islingtonsetpull_requests: + pull_request13510
2019-05-27 23:44:24vstinnersetmessages: + msg343709
2019-05-27 23:08:12vstinnersetmessages: + msg343700
2019-05-27 23:07:10vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request13507
2019-05-27 16:04:33pitrousetmessages: + msg343653
2019-05-27 16:02:19vstinnersetmessages: + msg343652
2019-05-26 14:54:40pitroucreate