Bug report
Bug description:
In BufferedRWPairTest.test_readinto a BufferedRWPair is created but not explicitly closed which results in it being Garbage Collected (GC). During GC the destruction order often results in an unraisable exception. This can be reliably reproduced by modifying the test to end with support.gc_collect(). The BufferedRWPair should cleanup reliably in this case.
| def test_readinto(self): | |
| for method in ("readinto", "readinto1"): | |
| with self.subTest(method): | |
| pair = self.tp(self.BytesIO(b"abcdef"), self.MockRawIO()) | |
| data = byteslike(b'\0' * 5) | |
| self.assertEqual(getattr(pair, method)(data), 5) | |
| self.assertEqual(bytes(data), b"abcde") |
Warning -- Unraisable exception Exception ignored while finalizing file <_io.BufferedRWPair object at 0x7fd9d7577950>: Traceback (most recent call last): File "<checkout_dir>/cpython/Lib/test/support/__init__.py", line 837, in gc_collect gc.collect() ~~~~~~~~~~^^ ValueError: flush of closed file Warning -- Unraisable exception Exception ignored while finalizing file <_io.BufferedWriter>: Traceback (most recent call last): File "<checkout_dir>/cpython/Lib/test/support/__init__.py", line 837, in gc_collect gc.collect() ~~~~~~~~~~^^ ValueError: flush of closed file
Found while working on GH-138475
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux