python / python/cpython

threading.Thread: Add start=False parameter to start immediately the thread

Open
#155,334 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

It's common to create multiple threads, start them, and then join them. Example:

threads = [
    threading.Thread(target=run_a),
    threading.Thread(target=run_b),
]
for thread in threads:
    thread.start()
...
for thread in threads:
    thread.join()

I propose adding a start=False parameter to threading.Thread to start immediately the thread. The example would become:

threads = [
    threading.Thread(target=run_a, start=True),
    threading.Thread(target=run_b, start=True),
]
...
for thread in threads:
    thread.join()

The new parameter would solve the old issue gh-93293 which requests to return self in start(). The issue example:

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

for t in threads:
  t.join()

would become:

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

for t in threads:
  t.join()
Linked PRs
  • gh-155335

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the threading.Thread constructor and its start() and join() behavior, then inspect the linked work in gh-155335. Determine the API semantics and compatibility implications of starting during construction; done means the proposed usage works correctly without changing existing Thread behavior.

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
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.