Mailing List Archive

gh-76785: Fix Windows Refleak in test_interpreters (gh-117913)
https://github.com/python/cpython/commit/3831144f9c8ce0fd582a0830a9e48a8da85e166a
commit: 3831144f9c8ce0fd582a0830a9e48a8da85e166a
branch: main
author: Eric Snow <ericsnowcurrently@gmail.com>
committer: ericsnowcurrently <ericsnowcurrently@gmail.com>
date: 2024-04-15T20:16:37-06:00
summary:

gh-76785: Fix Windows Refleak in test_interpreters (gh-117913)

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.

files:
M Lib/test/test_interpreters/test_api.py
M Lib/test/test_interpreters/utils.py

diff --git a/Lib/test/test_interpreters/test_api.py b/Lib/test/test_interpreters/test_api.py
index 9a7c7f2f92ef21..2bd8bee4063920 100644
--- a/Lib/test/test_interpreters/test_api.py
+++ b/Lib/test/test_interpreters/test_api.py
@@ -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
diff --git a/Lib/test/test_interpreters/utils.py b/Lib/test/test_interpreters/utils.py
index 08768c07c28ebf..8e475816f04de4 100644
--- a/Lib/test/test_interpreters/utils.py
+++ b/Lib/test/test_interpreters/utils.py
@@ -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


@@ -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


_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-leave@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: list-python-checkins@lists.gossamer-threads.com