Skip to content

trulens.core.utils.threading

trulens.core.utils.threading

Threading Utilities.

Classes

Thread

Bases: Thread

Thread that wraps target with copy of context and stack.

App components that do not use this thread class might not be properly tracked.

Some libraries are doing something similar so this class may be less and less needed over time but is still needed at least for our own uses of threads.

ThreadPoolExecutor

Bases: ThreadPoolExecutor

A ThreadPoolExecutor that keeps track of the stack prior to each thread's invocation.

Apps that do not use this thread pool might not be properly tracked.

TP

Manager of thread pools.

Singleton.

Attributes
MAX_THREADS class-attribute instance-attribute
MAX_THREADS: int = 128

Maximum number of threads to run concurrently.

DEBUG_TIMEOUT class-attribute instance-attribute
DEBUG_TIMEOUT: Optional[float] = 600.0

How long to wait (seconds) for any task before restarting it.

Functions
submit
submit(
    func: Callable[[A], T],
    *args,
    timeout: Optional[float] = None,
    **kwargs
) -> Future[T]

Submit a task to run.

PARAMETER DESCRIPTION
func

Function to run.

TYPE: Callable[[A], T]

*args

Positional arguments to pass to the function.

DEFAULT: ()

timeout

How long to wait for the task to complete before killing it.

TYPE: Optional[float] DEFAULT: None

**kwargs

Keyword arguments to pass to the function.

DEFAULT: {}

shutdown
shutdown()

Shutdown the pools.