python / python/cpython

threading.Thread.start should return self

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

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

docs stdlib type-feature
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

I often write code like:

threads = []
for i in range(10):
  thread = threading.Thread(target=fn, args=(i,))
  thread.start()
  threads.append(thread)

for t in threads:
  t.join()

and would really prefer:

threads = [threading.Thread(target=fn, args=(i,)).start() for i in range(10)]

Is there a reason why start doesn't return self here: https://github.com/python/cpython/blob/3.10/Lib/threading.py#L940 ?

An alternative would be to add a start: bool = False param to the Thread constructor such that you can construct it with start=True. I'm not sure why you'd ever want to construct a Thread but not start it, so I wish that could default to true, but clearly it can't due to backwards compatibility.

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

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

はじめの一歩

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

調査の方向性

Lib/threading.py の Thread.start の付近(940 行目近くを参照)から始め、要求されている戻り値の動作を、issue にあるコンストラクターの代替案と比較してください。既存の Thread の使用を壊さずに API 設計を解決し、その結果の動作を文書化できれば完了です。

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

評価

技術スタック
python
領域
operating-systems
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

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

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