python / python/cpython

`multiprocessing.Pool` is incompatible with `concurrent.interpreters`

Open
#140,057 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.14 3.15 stdlib topic-multiprocessing topic-subinterpreters type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Trying to create a mutliprocessing.Pool in a sub-interpreter fails due to the use of daemon threads.

How I ran into it: as an experiment, I was trying to run pytest in a sub-interpreter (on its own test suite). One of the tests is using multiprocessing.Pool and fails. (There are other failures, particularly faulthandler and readline incompatibilities, but those are unrelated to this issue).

If mutliprocessing.Pool and concurrent.interpreters are fundamentally incompatible for some reason, perhaps it can be documented.

from concurrent import interpreters

interp = interpreters.create()

interp.exec("""
import multiprocessing
pool = multiprocessing.Pool()
""")

Traceback:

Traceback (most recent call last):
  File "x.py", line 5, in <module>
    interp.exec("""
    ~~~~~~~~~~~^^^^
    import multiprocessing
    ^^^^^^^^^^^^^^^^^^^^^^
    pool = multiprocessing.Pool()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    """)
    ^^^^
  File "/home/ran/.local/share/uv/python/cpython-3.14.0-linux-x86_64-gnu/lib/python3.14/concurrent/interpreters/__init__.py", line 212, in exec
    raise ExecutionFailed(excinfo)
concurrent.interpreters.ExecutionFailed: RuntimeError: daemon threads are disabled in this interpreter

Uncaught in the interpreter:

Traceback (most recent call last):
  File "<script>", line 3, in <module>
  File "/home/ran/.local/share/uv/python/cpython-3.14.0-linux-x86_64-gnu/lib/python3.14/multiprocessing/context.py", line 119, in Pool
    return Pool(processes, initializer, initargs, maxtasksperchild,
                context=self.get_context())
  File "/home/ran/.local/share/uv/python/cpython-3.14.0-linux-x86_64-gnu/lib/python3.14/multiprocessing/pool.py", line 233, in __init__
    self._worker_handler.daemon = True
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ran/.local/share/uv/python/cpython-3.14.0-linux-x86_64-gnu/lib/python3.14/threading.py", line 1207, in daemon
    raise RuntimeError('daemon threads are disabled in this interpreter')
RuntimeError: daemon threads are disabled in this interpreter

Link to relevant code:

https://github.com/python/cpython/blob/6481539a6d9692ddf13ab01baad1bc9133409413/Lib/multiprocessing/pool.py#L226-L253

I'd also note that multiprocessing.Queue uses daemon thread:

https://github.com/python/cpython/blob/6481539a6d9692ddf13ab01baad1bc9133409413/Lib/multiprocessing/queues.py#L178-L186

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-140238

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example on Python 3.14, then inspect Lib/multiprocessing/pool.py and Lib/multiprocessing/queues.py at the referenced daemon-thread code. Check linked PR gh-140238 and the surrounding concurrent.interpreters behavior before deciding whether the result should be a compatibility change or documentation; done means the incompatibility is resolved or clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.