GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GC of unclosed io.BuffererdRWPair after `.readinto` results in unraisable exception · Issue #138720 · python/cpython

GC of unclosed io.BuffererdRWPair after .readinto results in unraisable exception #138720

New issue
Copy link
New issue
Copy link
Closed
Closed
GC of unclosed io.BuffererdRWPair after .readinto results in unraisable exception#138720
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@cmaloney
cmaloney
opened on Sep 9, 2025
Issue body actions

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.

cpython/Lib/test/test_io/test_general.py

Lines 2281 to 2288 in 6bc65c3

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

Linked PRs

  • gh-138720: Make Buffered closed check match flush #138724
  • gh-138013: Remove load_tests in test_io.test_general #138771

Activity

  1. cmaloney
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 9, 2025
  2. cmaloney
    added a commit that references this issue on Sep 10, 2025

    pythongh-138720: Make Buffered closed check match flush

    e93877d
  3. picnixz
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Sep 10, 2025
  4. cmaloney
    added 3 commits that reference this issue on Sep 10, 2025

    pythongh-138720: Remove load_tests in test_io.test_general

    bf95939

    pythongh-138720: Remove load_tests in test_io.test_general

    ad64edb

    pythongh-138720: Remove load_tests in test_io.test_general

    f8509c3
  5. encukou
    added a commit that references this issue on Sep 18, 2025

    gh-138720: Make Buffered closed check match flush (GH-138724)

    db68bfc
  6. cmaloney
    closed this as completedon Sep 18, 2025
  7. markqvist
    added a commit that references this issue on Nov 2, 2025

    Workaround for python/cpython#138720

    0896df0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.