ThreadSet
ThreadSet
¶
A container for sets of threads.
It provides boilerplate-removing utilities for handling standard library threads.
See Python's threading.Thread
documentation for general information on Python threads.
Methods:
-
__init__–You can initialize a
ThreadSetwith any threads you already defined: -
with_args–```python
-
repeat–```python
-
target–```python
-
start–Start the threads in this
ThreadSet. -
join–Join the threads in this
ThreadSet. -
start_and_join–Start the threads in this
ThreadSet, then join them. -
is_alive–Call
Thread.is_alive() -
any_is_alive–```python
-
all_are_alive–```python
-
all_are_not_alive–```python
-
__or__–Returns a new
ThreadSetcontaining all the threads in the operands, -
__ior__–Adds the threads in the right operand into this
ThreadSet. -
__len__–Returns the number of threads contained in this
ThreadSet.
__init__
¶
__init__(*threads: Thread)
You can initialize a ThreadSet with any threads you already defined:
class MyCustomThreadSubclass(threading.Thread):
...
threads = ThreadSet(
MyCustomThreadSubclass(...),
threading.Thread(...),
)
threads.start_and_join()
You can create unions of ThreadSets:
readers = ThreadSet(...)
readers.start()
writers = ThreadSet(...)
writers.start()
(readers | writers).join()
You can create a ThreadSet in a function definition, using with_args(),
repeat(), or target:
With ThreadSet.target, function typing
information is kept:
with_args
classmethod
¶
repeat
classmethod
¶
target
classmethod
¶
join
¶
start_and_join
¶
start_and_join(join_timeout: float | None = None)
Start the threads in this ThreadSet, then join them.