Generic utilities#
- async commons.sleep_with_condition(seconds: float, condition: partial | Callable[[Any], bool] | Callable[[Any], Coroutine[Any, Any, bool]], *, interval: float = 5) None#
Sleep until either condition is True or we run out of seconds
- Parameters:
seconds (float) – How long to sleep for up to
condition –
Pass either: - A sync function to call which returns a bool - An async function to call which returns a bool
Note
If you wish to use arguments in you functions, pass an instance of
functools.partialinterval (float) –
How long to sleep in-between each condition check.
Defaults to 5 seconds.
- commons.exception_as_string(error: Exception) str#
Given an exception, return the traceback as a string.
- commons.exceptions_as_string(errors: Sequence[Exception]) str#
- Given a sequence of exceptions,
return the tracebacks as a string seperated by
— .
- commons.value_to_bool(value: str | bool | int | None) bool#
Convert a string representation of truth to true (1) or false (0). True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’.
Also handles the case the value is a bool or None
Raises ValueError if ‘val’ is anything else.