From 0cb09f9a8b6853757d09abf19b333616d410aeb8 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Wed, 1 Oct 2025 14:45:33 +0530 Subject: [PATCH 1/3] improve isolation of test_pending_call_creates_thread_subinterpreter --- Lib/test/test_capi/test_misc.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index 229a7c2afa8f8d..66f0f23bab79ad 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -1984,9 +1984,9 @@ def test_module_state_shared_in_global(self): @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()") @requires_subinterpreters def test_pending_call_creates_thread_subinterpreter(self): - interpreters = import_helper.import_module("concurrent.interpreters") - r, w = os.pipe() + # For better isolation, run the entire test in a different subprocess. source = f"""if True: + code = '''if True: import _testinternalcapi import threading import time @@ -1995,9 +1995,7 @@ def test_pending_call_creates_thread_subinterpreter(self): def output(): time.sleep(1) - os.write({w}, b"x") - os.close({w}) - + print("x") def callback(): threading.Thread(target=output).start() @@ -2007,15 +2005,19 @@ def create_pending_call(): time.sleep(1) _testinternalcapi.simple_pending_call(callback) - threading.Thread(target=create_pending_call).start() - """ + ''' + + import concurrent.interpreters as interpreters + interp = interpreters.create() - interp.exec(source) + interp.exec(code) interp.close() - data = os.read(r, 1) - self.assertEqual(data, b"x") - os.close(r) + """ + rc, out, err = assert_python_ok('-c', source) + self.assertEqual(rc, 0) + self.assertEqual(out, b"x\n") + self.assertEqual(err, b"") @requires_subinterpreters From 81f305fcd09719570c0848cb0ec93755b38f136f Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Wed, 1 Oct 2025 15:08:04 +0530 Subject: [PATCH 2/3] improve isolation of test_pending_call_creates_thread_subinterpreter --- Lib/test/test_capi/test_misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index 66f0f23bab79ad..3d36e7147a4e7d 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -1995,7 +1995,7 @@ def test_pending_call_creates_thread_subinterpreter(self): def output(): time.sleep(1) - print("x") + print("x", end="") def callback(): threading.Thread(target=output).start() @@ -2016,7 +2016,7 @@ def create_pending_call(): """ rc, out, err = assert_python_ok('-c', source) self.assertEqual(rc, 0) - self.assertEqual(out, b"x\n") + self.assertEqual(out, b"x") self.assertEqual(err, b"") From 792c27f6c7e2c633104aaf5c82ac73cfd3e8d148 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Wed, 1 Oct 2025 17:24:31 +0530 Subject: [PATCH 3/3] remove marker --- Lib/test/test_capi/test_misc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index 3d36e7147a4e7d..6f1bcbe8454eb8 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -1981,7 +1981,6 @@ def test_module_state_shared_in_global(self): self.assertEqual(main_attr_id, subinterp_attr_id) @threading_helper.requires_working_threading() - @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()") @requires_subinterpreters def test_pending_call_creates_thread_subinterpreter(self): # For better isolation, run the entire test in a different subprocess.