Skip to content

ResourceWarning: unclosed file on buildbots from test_frame #96696

Closed
@sweeneyde

Description

@sweeneyde

Example warning output from https://buildbot.python.org/all/#/builders/558/builds/802 :

/home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py:258: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py' mode='r' encoding='UTF-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
./home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py:258: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py' mode='r' encoding='UTF-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
./home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py:258: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py' mode='r' encoding='UTF-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
./home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py:258: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py' mode='r' encoding='UTF-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
./home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py:258: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py' mode='r' encoding='UTF-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
./home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py:258: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/dje/cpython-buildarea/pull_request.edelsohn-fedora-z.refleak/build/Lib/test/test_frame.py' mode='r' encoding='UTF-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback

I believe this is related to the following delicate test case:

class TestIncompleteFrameAreInvisible(unittest.TestCase):
def test_issue95818(self):
#See GH-95818 for details
import gc
self.addCleanup(gc.set_threshold, *gc.get_threshold())
gc.set_threshold(1,1,1)
class GCHello:
def __del__(self):
print("Destroyed from gc")
def gen():
yield
fd = open(__file__)
l = [fd, GCHello()]
l.append(l)
del fd
del l
gen()

Presumably, we could either find a reproducer that doesn't leak resources, or suppress the warnings and/or run the test isolated in a separate process.

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixestestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions