From 2ed943e6ce4228e8b23c7c5d762c2e5247d76a60 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Sat, 15 Nov 2025 00:06:49 +0500 Subject: [PATCH] [3.14] GH-141509: Fix warning about remaining subinterpreters (GH-141528) (cherry picked from commit fa245df4a0848c15cf8d907c10fc92819994b866) Co-authored-by: Sergey Miryanov Co-authored-by: Peter Bierma --- Lib/test/test_interpreters/test_api.py | 1 + .../2025-11-14-00-19-45.gh-issue-141528.VWdax1.rst | 3 +++ Python/pylifecycle.c | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-11-14-00-19-45.gh-issue-141528.VWdax1.rst diff --git a/Lib/test/test_interpreters/test_api.py b/Lib/test/test_interpreters/test_api.py index c5a1743e7fdedf..e88fd399dfba38 100644 --- a/Lib/test/test_interpreters/test_api.py +++ b/Lib/test/test_interpreters/test_api.py @@ -431,6 +431,7 @@ def test_cleanup_in_repl(self): exit()""" stdout, stderr = repl.communicate(script) self.assertIsNone(stderr) + self.assertIn(b"Interpreter.close()", stdout) self.assertNotIn(b"Traceback", stdout) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-14-00-19-45.gh-issue-141528.VWdax1.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-14-00-19-45.gh-issue-141528.VWdax1.rst new file mode 100644 index 00000000000000..a51aa49522866b --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-14-00-19-45.gh-issue-141528.VWdax1.rst @@ -0,0 +1,3 @@ +Suggest using :meth:`concurrent.interpreters.Interpreter.close` instead of the +private ``_interpreters.destroy`` function when warning about remaining subinterpreters. +Patch by Sergey Miryanov. diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 5b9ce617a48676..f5fbdeedac34ad 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2517,7 +2517,7 @@ finalize_subinterpreters(void) (void)PyErr_WarnEx( PyExc_RuntimeWarning, "remaining subinterpreters; " - "destroy them with _interpreters.destroy()", + "close them with Interpreter.close()", 0); /* Swap out the current tstate, which we know must belong