From 7cfab1a30559bf5da4efafc66112da3b46aa1e5b Mon Sep 17 00:00:00 2001 From: Aurel Wildfellner <201101774+aurelwildfellner@users.noreply.github.com> Date: Thu, 5 Mar 2026 13:44:17 +0100 Subject: [PATCH 1/2] Add test_unclosed_interpreter_on_fork to cover gh-139759 --- Lib/test/test_interpreters/test_stress.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Lib/test/test_interpreters/test_stress.py b/Lib/test/test_interpreters/test_stress.py index 56bfc12f951f79..30b84aa323bd2d 100644 --- a/Lib/test/test_interpreters/test_stress.py +++ b/Lib/test/test_interpreters/test_stress.py @@ -1,3 +1,4 @@ +import os import threading import unittest @@ -82,6 +83,24 @@ def test_create_interpreter_no_memory(self): with support.inject_memory_error_cm(0, 1): _interpreters.create() + @support.requires_fork() + def test_unclosed_interpreter_on_fork(self): + interp = interpreters.create() + interp.exec("pass") + + fds = os.pipe() + pid = os.fork() + + if pid == 0: + os.close(fds[0]) + os.write(fds[1], b"OK") + os._exit(0) + else: + os.close(fds[1]) + self.addCleanup(os.close, fds[0]) + value = os.read(fds[0], 100) + self.assertEqual(value, b"OK") + if __name__ == '__main__': # Test needs to be a package, so we can do relative imports. From 1fdc86af06cff03503cae6a042c4179d38ff260d Mon Sep 17 00:00:00 2001 From: Aurel Wildfellner <201101774+aurelwildfellner@users.noreply.github.com> Date: Fri, 23 Oct 2026 15:09:27 +0200 Subject: [PATCH 2/2] add ignore_fork_in_thread_deprecation_warnings() decorator to test. --- Lib/test/test_interpreters/test_stress.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_interpreters/test_stress.py b/Lib/test/test_interpreters/test_stress.py index 30b84aa323bd2d..a3689a2acb9336 100644 --- a/Lib/test/test_interpreters/test_stress.py +++ b/Lib/test/test_interpreters/test_stress.py @@ -5,6 +5,7 @@ from test import support from test.support import import_helper from test.support import threading_helper +from test.support import warnings_helper # Raise SkipTest if subinterpreters not supported. _interpreters = import_helper.import_module('_interpreters') from concurrent import interpreters @@ -83,6 +84,7 @@ def test_create_interpreter_no_memory(self): with support.inject_memory_error_cm(0, 1): _interpreters.create() + @warnings_helper.ignore_fork_in_thread_deprecation_warnings() @support.requires_fork() def test_unclosed_interpreter_on_fork(self): interp = interpreters.create()