From df6db351bf199e20c1a03f3bdd4757c221adad3f Mon Sep 17 00:00:00 2001 From: Xuanteng Huang Date: Fri, 17 Oct 2025 15:47:25 +0800 Subject: [PATCH 1/3] create subinterp with `allow_daemon_threads=True` --- Lib/concurrent/interpreters/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/concurrent/interpreters/__init__.py b/Lib/concurrent/interpreters/__init__.py index ea4147ee9a25da..e787405729146e 100644 --- a/Lib/concurrent/interpreters/__init__.py +++ b/Lib/concurrent/interpreters/__init__.py @@ -62,7 +62,8 @@ def __str__(self): def create(): """Return a new (idle) Python interpreter.""" - id = _interpreters.create(reqrefs=True) + config = _interpreters.new_config('isolated', allow_daemon_threads=True) + id = _interpreters.create(config, reqrefs=True) return Interpreter(id, _ownsref=True) From dd5420b6e5e659faf2ae3b60db0ed04f67f6fdf3 Mon Sep 17 00:00:00 2001 From: Xuanteng Huang Date: Fri, 17 Oct 2025 16:07:17 +0800 Subject: [PATCH 2/3] add test --- .../test_concurrent_futures/test_process_pool.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Lib/test/test_concurrent_futures/test_process_pool.py b/Lib/test/test_concurrent_futures/test_process_pool.py index 9685f980119a0e..b3378f08184a99 100644 --- a/Lib/test/test_concurrent_futures/test_process_pool.py +++ b/Lib/test/test_concurrent_futures/test_process_pool.py @@ -213,6 +213,18 @@ def test_max_tasks_early_shutdown(self): for i, future in enumerate(futures): self.assertEqual(future.result(), mul(i, i)) + def test_subinterpreter(self): + from concurrent import interpreters + import textwrap + + interp = interpreters.create() + interp.exec(textwrap.dedent(""" + import multiprocessing + pool = multiprocessing.Pool() + pool.close() + """)) + interp.close() + @warnings_helper.ignore_fork_in_thread_deprecation_warnings() def test_python_finalization_error(self): # gh-109047: Catch RuntimeError on thread creation From a80997673daacec1594f36b164a809899ea646bf Mon Sep 17 00:00:00 2001 From: Xuanteng Huang Date: Fri, 17 Oct 2025 16:20:41 +0800 Subject: [PATCH 3/3] add news --- .../next/Library/2025-10-17-16-20-32.gh-issue-140057.Sb0H3r.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-10-17-16-20-32.gh-issue-140057.Sb0H3r.rst diff --git a/Misc/NEWS.d/next/Library/2025-10-17-16-20-32.gh-issue-140057.Sb0H3r.rst b/Misc/NEWS.d/next/Library/2025-10-17-16-20-32.gh-issue-140057.Sb0H3r.rst new file mode 100644 index 00000000000000..158f55315e0c65 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-17-16-20-32.gh-issue-140057.Sb0H3r.rst @@ -0,0 +1,2 @@ +Subinterpreters are created with ``allow_daemon_threads=True``, +allowing daemon threads in subinterpreters now.