Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignored exceptions in test_memoryio #81235

Closed
pitrou opened this issue May 26, 2019 · 7 comments
Closed

Ignored exceptions in test_memoryio #81235

pitrou opened this issue May 26, 2019 · 7 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented May 26, 2019

BPO 37054
Nosy @pitrou, @vstinner, @miss-islington
PRs
  • bpo-37054, _pyio: Fix BytesIO and TextIOWrapper __del__() #13601
  • [3.7] bpo-37054, _pyio: Fix BytesIO and TextIOWrapper __del__() (GH-13601) #13604
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-05-28.00:19:06.620>
    created_at = <Date 2019-05-26.14:54:40.062>
    labels = ['tests', '3.8', 'type-bug', 'library']
    title = 'Ignored exceptions in test_memoryio'
    updated_at = <Date 2019-05-28.00:19:06.615>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2019-05-28.00:19:06.615>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-28.00:19:06.620>
    closer = 'vstinner'
    components = ['Library (Lib)', 'Tests']
    creation = <Date 2019-05-26.14:54:40.062>
    creator = 'pitrou'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37054
    keywords = ['patch']
    message_count = 7.0
    messages = ['343552', '343652', '343653', '343700', '343709', '343718', '343720']
    nosy_count = 3.0
    nosy_names = ['pitrou', 'vstinner', 'miss-islington']
    pr_nums = ['13601', '13604']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37054'
    versions = ['Python 3.8']

    @pitrou
    Copy link
    Member Author

    pitrou commented May 26, 2019

    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 bpo-18748.

    @pitrou pitrou added 3.8 only security fixes stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels May 26, 2019
    @vstinner
    Copy link
    Member

    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.

    @pitrou
    Copy link
    Member Author

    pitrou commented May 27, 2019

    Or to add _buffer = None at the class level.

    @vstinner
    Copy link
    Member

    Antoine:

    Or to add _buffer = None at the class level.

    Ok, I wrote bpo-13601 to implement this idea and fix test_memoryio warnings.

    @vstinner
    Copy link
    Member

    New changeset a356841 by Victor Stinner in branch 'master':
    bpo-37054, _pyio: Fix BytesIO and TextIOWrapper __del__() (GH-13601)
    a356841

    @miss-islington
    Copy link
    Contributor

    New changeset 0f352d4 by Miss Islington (bot) in branch '3.7':
    bpo-37054, _pyio: Fix BytesIO and TextIOWrapper __del__() (GH-13601)
    0f352d4

    @vstinner
    Copy link
    Member

    Thanks for the report Antoine. It is now fixed in 3.7 and master branches.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants