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

test_io logs Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0> warnings #81404

Closed
vstinner opened this issue Jun 10, 2019 · 10 comments
Labels
3.8 only security fixes 3.9 only security fixes tests Tests in the Lib/test dir

Comments

@vstinner
Copy link
Member

BPO 37223
Nosy @vstinner
PRs
  • bpo-37223: test_io: silence destructor errors #13954
  • bpo-37223: io.BufferedWrite.close() don't call flush() if already closed #13999
  • bpo-37223: Second call to BufferedWrite.close() does nothing #14028
  • bpo-37223, test_io: silence last 'Exception ignored in:' #14029
  • [3.8] bpo-37223: test_io: silence destructor errors #14031
  • 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-06-12.22:24:34.107>
    created_at = <Date 2019-06-10.23:45:19.834>
    labels = ['3.8', 'tests', '3.9']
    title = 'test_io logs Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0> warnings'
    updated_at = <Date 2019-06-12.22:24:34.107>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2019-06-12.22:24:34.107>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-06-12.22:24:34.107>
    closer = 'vstinner'
    components = ['Tests']
    creation = <Date 2019-06-10.23:45:19.834>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37223
    keywords = ['patch']
    message_count = 10.0
    messages = ['345156', '345158', '345159', '345161', '345165', '345166', '345298', '345416', '345421', '345423']
    nosy_count = 1.0
    nosy_names = ['vstinner']
    pr_nums = ['13954', '13999', '14028', '14029', '14031']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue37223'
    versions = ['Python 3.8', 'Python 3.9']

    @vstinner
    Copy link
    Member Author

    bpo-18748 modified io.IOBase finalizer to no longer silence close() exception in develoment and in debug mode.

    The commit 472f794 fixed a few destructor errors in test_io, but there are still a few:

    test_uninitialized (test.test_io.PyBufferedReaderTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 814, in close
        if self.raw is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 836, in raw
        return self._raw
    AttributeError: 'BufferedReader' object has no attribute '_raw'
    ok
    
    test_max_buffer_size_removal (test.test_io.PyBufferedWriterTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1299, in close
        with self._write_lock:
    AttributeError: 'BufferedWriter' object has no attribute '_write_lock'
    ok
    
    test_misbehaved_io (test.test_io.PyBufferedWriterTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1308, in close
        self.flush()
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 1269, in flush
        self._flush_unlocked()
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 1285, in _flush_unlocked
        raise OSError("write() returned incorrect number of bytes")
    OSError: write() returned incorrect number of bytes
    ok
    
    test_uninitialized (test.test_io.PyBufferedWriterTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1299, in close
        with self._write_lock:
    AttributeError: 'BufferedWriter' object has no attribute '_write_lock'
    ok
    
    test_writer_close_error_on_close (test.test_io.CBufferedRWPairTest) ...
    Exception ignored in: <_io.BufferedWriter>
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/unittest/case.py", line 611, in _callTestMethod
        method()
    ValueError: flush of closed file
    ok
    
    test_constructor_max_buffer_size_removal (test.test_io.PyBufferedRWPairTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1377, in close
        self.reader.close()
    AttributeError: 'BufferedRWPair' object has no attribute 'reader'
    ok
    
    test_constructor_with_not_readable (test.test_io.PyBufferedRWPairTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1377, in close
        self.reader.close()
    AttributeError: 'BufferedRWPair' object has no attribute 'reader'
    ok
    
    test_constructor_with_not_writeable (test.test_io.PyBufferedRWPairTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1377, in close
        self.reader.close()
    AttributeError: 'BufferedRWPair' object has no attribute 'reader'
    ok
    
    test_isatty (test.test_io.PyBufferedRWPairTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1377, in close
        self.reader.close()
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 814, in close
        if self.raw is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 814, in close
        if self.raw is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1300, in close
        if self.raw is None or self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1377, in close
        self.reader.close()
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 814, in close
        if self.raw is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 814, in close
        if self.raw is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1300, in close
        if self.raw is None or self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1377, in close
        self.reader.close()
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 814, in close
        if self.raw is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 814, in close
        if self.raw is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1300, in close
        if self.raw is None or self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1377, in close
        self.reader.close()
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 814, in close
        if self.raw is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 814, in close
        if self.raw is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1300, in close
        if self.raw is None or self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'SelectableIsAtty' object has no attribute 'closed'
    ok
    
    test_uninitialized (test.test_io.PyBufferedRWPairTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1377, in close
        self.reader.close()
    AttributeError: 'BufferedRWPair' object has no attribute 'reader'
    ok
    
    test_destructor (test.test_io.CBufferedRandomTest) ...
    Exception ignored in: <_io.BufferedRWPair object at 0x7f2f3c5842f0>
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/test/support/__init__.py", line 1627, in gc_collect
        gc.collect()
    ValueError: flush of closed file
    
    Exception ignored in: <_io.BufferedWriter>
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/test/support/__init__.py", line 1627, in gc_collect
        gc.collect()
    ValueError: flush of closed file
    ok
    
    test_misbehaved_io (test.test_io.CBufferedRandomTest) ...
    Exception ignored in: <_io.BufferedRandom>
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/test/test_io.py", line 2306, in test_misbehaved_io
        BufferedReaderTest.test_misbehaved_io(self)
    OSError: Raw stream returned invalid position -123
    
    Exception ignored in: <_io.BufferedRandom>
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/test/test_io.py", line 2307, in test_misbehaved_io
        BufferedWriterTest.test_misbehaved_io(self)
    OSError: Raw stream returned invalid position -123
    ok
    
    test_write_non_blocking (test.test_io.CBufferedRandomTest) ...
    Exception ignored in: <_io.BufferedRandom>
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/unittest/case.py", line 611, in _callTestMethod
        method()
    io.UnsupportedOperation: seek
    ok
    
    test_max_buffer_size_removal (test.test_io.PyBufferedRandomTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1299, in close
        with self._write_lock:
    AttributeError: 'BufferedRandom' object has no attribute '_write_lock'
    ok
    
    test_misbehaved_io (test.test_io.PyBufferedRandomTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1308, in close
        self.flush()
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 1269, in flush
        self._flush_unlocked()
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 1285, in _flush_unlocked
        raise OSError("write() returned incorrect number of bytes")
    OSError: write() returned incorrect number of bytes
    ok
    
    test_uninitialized (test.test_io.PyBufferedRandomTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1299, in close
        with self._write_lock:
    AttributeError: 'BufferedRandom' object has no attribute '_write_lock'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 1299, in close
        with self._write_lock:
    AttributeError: 'BufferedRandom' object has no attribute '_write_lock'
    ok
    
    test_destructor (test.test_io.PyTextIOWrapperTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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/test/test_io.py", line 2817, in close
        l.append(self.getvalue())
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 896, in getvalue
        raise ValueError("getvalue on closed file")
    ValueError: getvalue on closed file
    ok
    
    test_issue22849 (test.test_io.PyTextIOWrapperTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
    AttributeError: 'F' object has no attribute 'closed'
    ok
    
    test_repr (test.test_io.PyTextIOWrapperTest) ...
    Exception ignored in: <function IOBase.__del__ at 0x7f2f3c73e4b0>
    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 2161, in close
        if self.buffer is not None and not self.closed:
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 2169, in closed
        return self.buffer.closed
      File "/home/vstinner/prog/python/master/Lib/_pyio.py", line 840, in closed
        return self.raw.closed
    AttributeError: 'NoneType' object has no attribute 'closed'
    ok

    List of failing tests:

    test.test_io.CBufferedRWPairTest.test_writer_close_error_on_close
    test.test_io.CBufferedRandomTest.test_destructor
    test.test_io.CBufferedRandomTest.test_misbehaved_io
    test.test_io.CBufferedRandomTest.test_write_non_blocking
    test.test_io.PyBufferedRWPairTest.test_constructor_max_buffer_size_removal
    test.test_io.PyBufferedRWPairTest.test_constructor_with_not_readable
    test.test_io.PyBufferedRWPairTest.test_constructor_with_not_writeable
    test.test_io.PyBufferedRWPairTest.test_isatty
    test.test_io.PyBufferedRWPairTest.test_uninitialized
    test.test_io.PyBufferedRandomTest.test_max_buffer_size_removal
    test.test_io.PyBufferedRandomTest.test_misbehaved_io
    test.test_io.PyBufferedRandomTest.test_uninitialized
    test.test_io.PyBufferedReaderTest.test_uninitialized
    test.test_io.PyBufferedWriterTest.test_max_buffer_size_removal
    test.test_io.PyBufferedWriterTest.test_misbehaved_io
    test.test_io.PyBufferedWriterTest.test_uninitialized
    test.test_io.PyTextIOWrapperTest.test_destructor
    test.test_io.PyTextIOWrapperTest.test_issue22849
    test.test_io.PyTextIOWrapperTest.test_repr

    @vstinner vstinner added 3.8 only security fixes 3.9 only security fixes tests Tests in the Lib/test dir labels Jun 10, 2019
    @vstinner
    Copy link
    Member Author

    See also bpo-36918 (test_urllib) and bpo-37069 (regrtest: log unraisable exceptions and uncaught thread exceptions).

    @vstinner
    Copy link
    Member Author

    PR 13952 fix many errors, but not of all them.

    test_io.PyBufferedWriterTest.test_misbehaved_io() logs a warning, whereas test_io.CBufferedWriterTest.test_misbehaved_io() doesn't. It seems like _pyio.BufferedWriter lacks bpo-32228 fix.

    Extract of the C implementation:

    static PyObject *
    _bufferedwriter_flush_unlocked(buffered *self)
    {
    ...

    if (!VALID_WRITE_BUFFER(self) || self->write_pos == self->write_end)
        goto end;
    
        /* First, rewind */
        rewind = RAW_OFFSET(self) + (self->pos - self->write_pos);
        if (rewind != 0) {
            n = _buffered_raw_seek(self, -rewind, 1);
            if (n < 0) {
                goto error;
            }
            self->raw_pos -= rewind;
        }
        ...

    end:
    /* This ensures that after return from this function,
    VALID_WRITE_BUFFER(self) returns false.

       This is a required condition because when a tell() is called
       after flushing and if VALID_READ_BUFFER(self) is false, we need
       VALID_WRITE_BUFFER(self) to be false to have
       RAW_OFFSET(self) == 0.
    
           Issue: https://bugs.python.org/issue32228 */
        _bufferedwriter_reset_buf(self);
        Py_RETURN_NONE;
    
    error:
        return NULL;
    }

    @vstinner
    Copy link
    Member Author

    New changeset 4f6f7c5 by Victor Stinner in branch 'master':
    bpo-18748: Fix _pyio.IOBase destructor (closed case) (GH-13952)
    4f6f7c5

    @vstinner
    Copy link
    Member Author

    New changeset b589cef by Victor Stinner in branch 'master':
    bpo-37223: test_io: silence destructor errors (GH-13954)
    b589cef

    @vstinner
    Copy link
    Member Author

    Once bpo-36918 will be fixed, I will backport changes to Python 3.8.

    @vstinner
    Copy link
    Member Author

    Oh. There are still 3 errors in 2 tests:

    test_writer_close_error_on_close (test.test_io.CBufferedRWPairTest) ... Exception ignored in: <_io.BufferedWriter>
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/unittest/case.py", line 611, in _callTestMethod
        method()
    ValueError: flush of closed file
    ok
    
    test_destructor (test.test_io.CBufferedRandomTest) ... Exception ignored in: <_io.BufferedRWPair object at 0x7fc9d1c230b0>
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/test/support/__init__.py", line 1627, in gc_collect
        gc.collect()
    ValueError: flush of closed file
    Exception ignored in: <_io.BufferedWriter>
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/test/support/__init__.py", line 1627, in gc_collect
        gc.collect()
    ValueError: flush of closed file
    ok

    @vstinner
    Copy link
    Member Author

    New changeset 913fa1c by Victor Stinner in branch 'master':
    bpo-37223, test_io: silence last 'Exception ignored in:' (GH-14029)
    913fa1c

    @vstinner
    Copy link
    Member Author

    New changeset c15a682 by Victor Stinner in branch '3.8':
    bpo-37223: test_io: silence destructor errors (GH-14031)
    c15a682

    @vstinner
    Copy link
    Member Author

    Ok, all errors have been fixed in 3.8 and master. I close the issue.

    @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 3.9 only security fixes tests Tests in the Lib/test dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant