MultiThread

class lib.multithreading.MultiThread(target: Callable, *args, thread_count: int = 1, name: str | None = None, **kwargs)

Bases: object

Threading 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 None a unique name is constructed of the form {target.__name__}_N where N is an incrementing integer. Default: None

  • kwargs – keyword arguments for the target invocation. Default: {}.

Attributes Summary

errors

List of thread error values

has_error

True if a thread has errored, otherwise False

name

The name of the thread

Methods Summary

check_and_raise_error()

Checks for errors in thread and raises them in caller.

completed()

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

True if a thread has errored, otherwise False

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:

True if all threads have completed otherwise False

is_alive() bool

Check if any threads are still alive

Return type:

True if any threads are alive. False if 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:

True if all threads have completed otherwise False

property errors: list[tuple[type[BaseException], BaseException, TracebackType] | tuple[Any, Any, Any]]

List of thread error values

Type:

list

property has_error: bool

True if a thread has errored, otherwise False

is_alive() bool

Check if any threads are still alive

Return type:

True if any threads are alive. False if 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