module emote.utils.threading

Thread-related utilities and tools.

Classes

class LockedResource(Generic[T]):

Context manager for a lock and a resource. Only giving access to the resource when locked. Works well when paired with [empyc.types.Ref] for primitive types as well.

Usage:

resource = LockedResource([])
with resource as inner_list:
     inner_list.append(1)

Methods

def __init__(self, data) -> None

Create a new LockedResource, with the provided data.

Arguments:

  • data(T): The data to lock
def swap(self, new_resource) -> T

Replace the contained resource with the provided new resource, returning the previous resource. This operation is atomic.

Arguments:

  • new_resource(T): The resource to lock after the swap

Returns:

  • The previously guarded data

class AtomicContainer:

Container that allows atomic set, get, take operations.

Methods

def __init__(self, initial_data) -> None

Arguments:

  • initial_data(Any)
def take(self) -> Any
def read(self) -> Any
def set(self, value) -> None

class AtomicInt:

Methods

def __init__(self, value) -> None
def swap(self, value) -> None
def increment(self, value) -> None

Increments the integer and returns the previous value.

Arguments:

  • value(int) (default: 1)

class TracedLock:

Methods

def __init__(self, lock_class) -> None