calypso.dispatchers.orchestrator.toolkit module

class calypso.dispatchers.orchestrator.toolkit.JobStatusEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: JSONEncoder

default(obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
class calypso.dispatchers.orchestrator.toolkit.ProcInfo(stdout: str, stderr: str, returncode: int)

Bases: object

returncode: int
stderr: str
stdout: str
class calypso.dispatchers.orchestrator.toolkit.ThreadLock

Bases: object

A simple class for managing thread locks, ensuring mutual exclusion in multi-threaded environments. It encapsulates a threading.Lock object with a more straightforward usage pattern.

Class for handling thread synchronization using a lock.

__init__()

Initialize the ThreadLock instance.

acquire()

Acquire the lock. Blocks if the lock is already held.

release()

Release the lock. Only the thread that holds the lock can release it.

__enter__()

Enter the runtime context related to this lock. Acquires the lock.

__exit__(exc_type, exc_val, exc_tb)

Exit the runtime context. Releases the lock and re-raises any captured exception.

acquire()

Acquire the lock.

Blocks the current thread until it can acquire the lock.

release()

Release the lock.

The lock must be held by the current thread.

class calypso.dispatchers.orchestrator.toolkit.ThreadWithException(*args, **kwargs)

Bases: Thread

A thread class that captures exceptions.

_exception

Captured exception from the thread, if any.

Type:

Exception or None

get_exception()

Get the captured exception.

Returns:

The captured exception if any, otherwise None.

Return type:

Exception or None

run()

Run method overridden to capture exceptions.

This method calls the target function and captures any exceptions that occur.

class calypso.dispatchers.orchestrator.toolkit.TimeParser(hours=0, minutes=0, seconds=0)

Bases: object

classmethod from_list(time_list)
classmethod from_minutes(total_minutes)
classmethod from_seconds(total_seconds)
classmethod from_str(time_str)
static check_value(minutes=0, seconds=0)
get_hours()
get_minutes()
get_seconds()
to_string(str_format='normal')
calypso.dispatchers.orchestrator.toolkit.hashstr(name: str)

generate a unique hash value for a given name.

Parameters:

name (Iterable) – to be hashed.

Returns:

hashed str.

Return type:

str

calypso.dispatchers.orchestrator.toolkit.lower_case_key(machine_dict)

Convert all keys in the input dictionary to lowercase.

Parameters:

machine_dict (dict) – The dictionary whose keys need to be transformed to lowercase.

Returns:

A new dictionary with all keys in lowercase.

Return type:

dict

calypso.dispatchers.orchestrator.toolkit.split_list(target_list, ratios=None, group_size=None)

split a list into several lists according to ratios or group_size.

Parameters:
  • target_list (list) – A list to be sperated.

  • ratios (list or None, optional) – target list can be splited into len(ratios) parts according to ratios , by default None

  • group_size (int or None, optional) – target list can be splited into len(target_list)/group_size parts according to group_size , by default None

Returns:

A list consisting of sperated lists.

Return type:

list