threading.Thread.start should return self
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Lib/threading.py around Thread.start, referenced near line 940, and compare the requested return behavior with the constructor alternative in the issue. Done means resolving the API design and documenting the resulting behavior without breaking existing Thread usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100