|
30 | 30 | 'setprofile', 'settrace', 'local', 'stack_size', |
31 | 31 | 'excepthook', 'ExceptHookArgs', 'gettrace', 'getprofile', |
32 | 32 | 'serialize_iterator', 'synchronized_iterator', 'concurrent_tee', |
33 | | - 'setprofile_all_threads','settrace_all_threads'] |
| 33 | + 'setprofile_all_threads','settrace_all_threads', |
| 34 | + 'run', 'run_daemon'] |
34 | 35 |
|
35 | 36 | # Rename some stuff so "from threading import *" is safe |
36 | 37 | _start_joinable_thread = _thread.start_joinable_thread |
@@ -1664,6 +1665,19 @@ def enumerate(): |
1664 | 1665 | with _active_limbo_lock: |
1665 | 1666 | return list(_active.values()) + list(_limbo.values()) |
1666 | 1667 |
|
| 1668 | +def run(func, /, *args, **kwargs): |
| 1669 | + """Return a running Thread object of func(*args, **kwargs).""" |
| 1670 | + thread = Thread(target=func, name=func.__name__, args=args, kwargs=kwargs) |
| 1671 | + thread.start() |
| 1672 | + return thread |
| 1673 | + |
| 1674 | +def run_daemon(func, /, *args, **kwargs): |
| 1675 | + """Return a running daemonic Thread object of func(*args, **kwargs).""" |
| 1676 | + thread = Thread(target=func, name=func.__name__, args=args, kwargs=kwargs) |
| 1677 | + thread.daemon = True |
| 1678 | + thread.start() |
| 1679 | + return thread |
| 1680 | + |
1667 | 1681 |
|
1668 | 1682 | _threading_atexits = [] |
1669 | 1683 | _SHUTTING_DOWN = False |
|
0 commit comments