MultiThread
- class lib.multithreading.MultiThread(target: Callable, *args, thread_count: int = 1, name: str | None = None, **kwargs)
Bases:
objectThreading for IO heavy ops. Catches errors in thread and rethrows to parent.
- Parameters:
target (Callable) – The callable object to be invoked by the run() method.
args – The argument tuple for the target invocation. Default: ().
thread_count (int) – The number of threads to use. Default: 1
name (str | None) – The thread name. if
Nonea unique name is constructed of the form {target.__name__}_N where N is an incrementing integer. Default:Nonekwargs – keyword arguments for the target invocation. Default: {}.
Attributes Summary
List of thread error values
Trueif a thread has errored, otherwiseFalseThe name of the thread
Methods Summary
Checks for errors in thread and raises them in caller.
Check if all threads have completed
is_alive()Check if any threads are still alive
join()Join the running threads, catching and re-raising any errors
start()Start all the threads for the given method, args and kwargs
Attributes Documentation
- errors
List of thread error values
- Type:
list
- has_error
Trueif a thread has errored, otherwiseFalse
- name
The name of the thread
Methods Documentation
- check_and_raise_error() None
Checks for errors in thread and raises them in caller.
- Raises:
Error – Re-raised error from within the thread
- Return type:
None
- completed() bool
Check if all threads have completed
- Return type:
Trueif all threads have completed otherwiseFalse
- is_alive() bool
Check if any threads are still alive
- Return type:
Trueif any threads are alive.Falseif no threads are alive
- join() None
Join the running threads, catching and re-raising any errors
Clear the list of threads for class instance re-use
- Return type:
None
- start() None
Start all the threads for the given method, args and kwargs
- Return type:
None
- check_and_raise_error() None
Checks for errors in thread and raises them in caller.
- Raises:
Error – Re-raised error from within the thread
- Return type:
None
- completed() bool
Check if all threads have completed
- Return type:
Trueif all threads have completed otherwiseFalse
- property errors: list[tuple[type[BaseException], BaseException, TracebackType] | tuple[Any, Any, Any]]
List of thread error values
- Type:
list
- property has_error: bool
Trueif a thread has errored, otherwiseFalse
- is_alive() bool
Check if any threads are still alive
- Return type:
Trueif any threads are alive.Falseif no threads are alive
- join() None
Join the running threads, catching and re-raising any errors
Clear the list of threads for class instance re-use
- Return type:
None
- property name: str
The name of the thread
- start() None
Start all the threads for the given method, args and kwargs
- Return type:
None