python / python/cpython

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

オープン
#140,057 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

3.14 3.15 stdlib topic-multiprocessing topic-subinterpreters type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Python 3.14 で例を再現し、その後、参照されている daemon-thread コードについて Lib/multiprocessing/pool.py と Lib/multiprocessing/queues.py を調査してください。結果を互換性の変更にすべきかドキュメントにすべきかを判断する前に、リンクされている PR gh-140238 と、周辺の concurrent.interpreters の動作を確認してください。非互換性が解消されるか、明確に文書化されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。