-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
gh-156131: threading: add run() and run_daemon() to start threads easily #156178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,8 @@ | |
| 'setprofile', 'settrace', 'local', 'stack_size', | ||
| 'excepthook', 'ExceptHookArgs', 'gettrace', 'getprofile', | ||
| 'serialize_iterator', 'synchronized_iterator', 'concurrent_tee', | ||
| 'setprofile_all_threads','settrace_all_threads'] | ||
| 'setprofile_all_threads','settrace_all_threads', | ||
| 'run', 'run_daemon'] | ||
|
|
||
| # Rename some stuff so "from threading import *" is safe | ||
| _start_joinable_thread = _thread.start_joinable_thread | ||
|
|
@@ -1664,6 +1665,19 @@ def enumerate(): | |
| with _active_limbo_lock: | ||
| return list(_active.values()) + list(_limbo.values()) | ||
|
|
||
| def run(func, /, *args, **kwargs): | ||
| """Return a running Thread object of func(*args, **kwargs).""" | ||
| thread = Thread(target=func, name=func.__name__, args=args, kwargs=kwargs) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
| thread.start() | ||
| return thread | ||
|
|
||
| def run_daemon(func, /, *args, **kwargs): | ||
| """Return a running daemonic Thread object of func(*args, **kwargs).""" | ||
| thread = Thread(target=func, name=func.__name__, args=args, kwargs=kwargs) | ||
| thread.daemon = True | ||
| thread.start() | ||
| return thread | ||
|
|
||
|
|
||
| _threading_atexits = [] | ||
| _SHUTTING_DOWN = False | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add :func:`threading.run` and :func:`threading.run_daemon` functions as | ||
| a convenient way to start threads. |
Uh oh!
There was an error while loading. Please reload this page.