Skip to content

Commit

Permalink
gh-76785: Fix Windows Refleak in test_interpreters (gh-117913)
Browse files Browse the repository at this point in the history
gh-117662 introduced some refleaks, or, rather, exposed some existing refleaks.  The leaks are coming when test.support.os_helper is imported in a "legacy" interpreter.  I've updated test.test_interpreters.utils to avoid importing os_helper, which fixes the leaks.  I'll address the root cause separately.
  • Loading branch information
ericsnowcurrently authored Apr 16, 2024
1 parent 757891e commit 3831144
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 0 additions & 3 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ def test_idempotent(self):

@requires_test_modules
def test_created_with_capi(self):
last = 0
for id, *_ in _interpreters.list_all():
last = max(last, id)
expected = _testinternalcapi.next_interpreter_id()
text = self.run_temp_from_capi(f"""
import {interpreters.__name__} as interpreters
Expand Down
10 changes: 7 additions & 3 deletions Lib/test/test_interpreters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import warnings

from test import support
from test.support import os_helper
from test.support import import_helper

_interpreters = import_helper.import_module('_xxsubinterpreters')
# We would use test.support.import_helper.import_module(),
# but the indirect import of test.support.os_helper causes refleaks.
try:
import _xxsubinterpreters as _interpreters
except ImportError as exc:
raise unittest.SkipTest(str(exc))
from test.support import interpreters


Expand Down Expand Up @@ -399,6 +402,7 @@ def ensure_closed(fd):
def temp_dir(self):
tempdir = tempfile.mkdtemp()
tempdir = os.path.realpath(tempdir)
from test.support import os_helper
self.addCleanup(lambda: os_helper.rmtree(tempdir))
return tempdir

Expand Down

0 comments on commit 3831144

Please sign in to comment.