From 449a7aa803c4cc076f1c00414dda7a3ae7e4e975 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 27 Jun 2026 14:49:22 +0300 Subject: [PATCH 1/2] gh-152391: Improve `test_interpreters.test_stress` test --- Lib/test/test_interpreters/test_stress.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_interpreters/test_stress.py b/Lib/test/test_interpreters/test_stress.py index 50d87a6ccd3cad..5331e65b7e093b 100644 --- a/Lib/test/test_interpreters/test_stress.py +++ b/Lib/test/test_interpreters/test_stress.py @@ -4,8 +4,6 @@ from test import support from test.support import import_helper from test.support import threading_helper -# Raise SkipTest if subinterpreters not supported. -_interpreters = import_helper.import_module('_interpreters') from concurrent import interpreters from concurrent.interpreters import InterpreterError from .utils import TestBase @@ -25,6 +23,7 @@ def test_create_many_sequential(self): del alive support.gc_collect() + @threading_helper.requires_working_threading() @support.bigmemtest(size=200, memuse=32*2**20, dry_run=False) def test_create_many_threaded(self, size): alive = [] @@ -44,6 +43,7 @@ def task(): @threading_helper.requires_working_threading() @support.bigmemtest(size=200, memuse=34*2**20, dry_run=False) def test_many_threads_running_interp_in_other_interp(self, size): + import_helper.import_module('_interpreters') start = threading.Event() interp = interpreters.create() @@ -78,11 +78,15 @@ def run(): @support.nomemtest def test_create_interpreter_no_memory(self): import _testcapi + _interpreters = import_helper.import_module('_interpreters') assertion = self.assertRaises(InterpreterError) _testcapi.set_nomemory(0, 1) - with assertion: - _interpreters.create() + try: + with assertion: + _interpreters.create() + finally: + _testcapi.remove_mem_hooks() if __name__ == '__main__': From 86be03494151c11819d79af6e3140e74841c8c27 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 27 Jun 2026 15:22:12 +0300 Subject: [PATCH 2/2] Fix CI --- Lib/test/test_interpreters/test_stress.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_interpreters/test_stress.py b/Lib/test/test_interpreters/test_stress.py index 5331e65b7e093b..50d2444a4c72d3 100644 --- a/Lib/test/test_interpreters/test_stress.py +++ b/Lib/test/test_interpreters/test_stress.py @@ -4,6 +4,8 @@ from test import support from test.support import import_helper from test.support import threading_helper +# Raise SkipTest if subinterpreters not supported. +_interpreters = import_helper.import_module('_interpreters') from concurrent import interpreters from concurrent.interpreters import InterpreterError from .utils import TestBase @@ -43,7 +45,6 @@ def task(): @threading_helper.requires_working_threading() @support.bigmemtest(size=200, memuse=34*2**20, dry_run=False) def test_many_threads_running_interp_in_other_interp(self, size): - import_helper.import_module('_interpreters') start = threading.Event() interp = interpreters.create() @@ -78,11 +79,10 @@ def run(): @support.nomemtest def test_create_interpreter_no_memory(self): import _testcapi - _interpreters = import_helper.import_module('_interpreters') assertion = self.assertRaises(InterpreterError) - _testcapi.set_nomemory(0, 1) try: + _testcapi.set_nomemory(0, 1) with assertion: _interpreters.create() finally: