Skip to content

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

Description

@vstinner

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),
]
forthreadinthreads:
thread.start()
...
forthreadinthreads:
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),
]
...
forthreadinthreads:
thread.join()

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

threads= []
foriinrange(10):
thread=threading.Thread(target=fn, args=(i,))
thread.start()
threads.append(thread)
fortinthreads:
t.join()

would become:

threads= [threading.Thread(target=fn, args=(i,), start=True) foriinrange(10)]
fortinthreads:
t.join()

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions