threading.Semaphore documentation is not internally consistent
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Documentation
threading.Semaphore has two methods, acquire() and release(). The documentation for acquire() states:
Exactly one thread will be awoken by each call to release().
The documentation for release() states:
Release a semaphore, incrementing the internal counter by n. When it was zero on entry and other threads are waiting for it to become larger than zero again, wake up n of those threads.
These statements cannot both be true. Which is correct? Technically, I suspect... neither. Though my guess is the latter is far closer to the truth.
The n parameter to release() was added in Python 3.9; before that development, the statement in acquire() would have been true. So I suspect the statement in the documentation for acquire() is simply old information, rendered obsolete by this new parameter.
However, the documentation for release() says it will wake up n threads. But what if fewer than n threads are waiting? It can't wake up threads that don't exist.
Someone should read the implementation of threading.Semaphore, figure out what its behavior actually is, and rewrite the documentation to accurately reflect that behavior. My suspicion is that this statement correctly describes its behavior:
If there are j threads blocked on
acquire(), and you callrelease(n), release will wake upmin(j, n)of those threads.
It might be nice to backport this change to all currently-supported versions, too.
Linked PRs
- gh-141243
- gh-141244
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず threading.Semaphore の実装を読み、その後、issue にリンクされている acquire() と release() のドキュメント項目を比較してください。両方の説明が実装と一貫して一致するようにドキュメントを更新し、待機中のスレッドが少ない場合の release(n) も含めて、サポート対象バージョンのドキュメント全体で文言を確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100