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) 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 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.