multiprocessing.Queue.empty() returns False after all producers have exited on Windows 3.13.3
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
On Windows 11 with CPython 3.13.3 official installer, Queue.empty() incorrectly returns False when the producer process has already terminated, allowing a later-started consumer to successfully get() all buffered items. This contradicts the documented behaviour that empty() is only reliable while producers are alive.
To Reproduce
Save as clean_test.py:
Python
from multiprocessing import Process, Queue
def x(q):
for i in range(4):
q.put(i)
def y(q):
cnt = 0
while True:
if q.empty():
break
q.get()
cnt += 1
print('实际 get 次数:', cnt)
if __name__ == '__main__':
q = Queue()
p1 = Process(target=x, args=(q,))
p2 = Process(target=y, args=(q,))
p1.start()
p1.join() # producer already dead
p2.start()
p2.join()
Run:
powershell
python clean_test.py
Expected behaviour
Should print 实际 get 次数: 0 (consumer sees empty queue).
Actual behaviour
Prints 实际 get 次数: 4 (consumer successfully gets all items).
Environment
OS: Windows 11 (build 22631)
Python: 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
Installer: official python.org x64 exe
File SHA-256: 4D8746575FF5D9062D159EB0C382589DBFEC56C942D23DA57E44CF1920312D57
Additional context
The same script always outputs 0 on Linux (CPython 3.11-3.13) and on Windows 10 with 3.11.
Appears to be Windows-specific and version-specific (3.13.3).
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
clean_test.py の再現コードから始め、Windows 11 上で CPython 3.13.3 を使って実行し、その後、issue に記載されている Windows 10 と Linux の結果と比較します。multiprocessing.Queue.empty() と producer/consumer のライフサイクルを調査します。Windows 3.13.3 のケースで、producer の終了後に 0 個の項目が報告され、比較対象の環境にリグレッションが発生していなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- operating-systems
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100