File descriptor leak using multiprocessing.Queue
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
"Too many open files" can occur with multiprocessing.Queue, even if the protocol used to work with the queue is correct.
The file descriptor leak can be demonstrated with two small programs:
File "ko.py"
import os
import multiprocessing
pid = os.getpid()
cmd = f'lsof -p {pid} | grep -i pipe | wc -l'
cmdfull = f'lsof -p {pid} | grep -i pipe'
queues = {}
for i in range(100):
queues[i] = multiprocessing.Queue()
os.system(cmd)
queues[i].close()
queues[i].join_thread()
os.system(cmd)
os.system(cmdfull)
File "ok.py"
import os
import multiprocessing
pid = os.getpid()
cmd = f'lsof -p {pid} | grep -i pipe | wc -l'
cmdfull = f'lsof -p {pid} | grep -i pipe'
queues = {}
for i in range(100):
queues[i] = multiprocessing.Queue()
queues[i].put('Hello')
os.system(cmd)
queues[i].close()
queues[i].join_thread()
os.system(cmd)
os.system(cmdfull)
An empty queue that remains empty is not abnormal (e.g., an error queue when no errors occur).
The workaround is to create a class extending multiprocessing.Queue, adding a close method that inserts an extra message into the queue before performing the actual close.
This issue can be observed on Linux and macOS. However, it is not specific to a particular operating system.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、サポート対象の Linux または macOS システムで ko.py と ok.py の再現コードを実行し、それぞれのファイルディスクリプタ数を比較します。次に、multiprocessing.Queue の close および join_thread のパスを調査します。空のキューを繰り返し閉じても lsof に表示されるディスクリプタが残らず、ok.py で示されている動作が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- operating-systems
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100