Skip to content

threading.Thread.start should return self #93293

Open
@tewalds

Description

@tewalds

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirstdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions