python / python/cpython

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

Offen
#140,057 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

3.14 3.15 stdlib topic-multiprocessing topic-subinterpreters type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das Beispiel mit Python 3.14 und untersuche anschließend Lib/multiprocessing/pool.py sowie Lib/multiprocessing/queues.py beim referenzierten Daemon-Thread-Code. Prüfe den verknüpften PR gh-140238 und das Verhalten von concurrent.interpreters im näheren Umfeld, bevor du entscheidest, ob das Ergebnis eine Kompatibilitätsänderung oder eine Dokumentation sein sollte; abgeschlossen ist die Aufgabe, wenn die Inkompatibilität behoben oder eindeutig dokumentiert ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.