utils
messageflux.utils
AggregatedException
ContextDidNotEndException
Bases: KwargsException
this exception is raised when elapsed seconds is called on a context that was not run
KwargsException
Bases: Exception
the basic exception type we use. adds the ability to add KWARGS to exception
ObservableEvent
Bases: Generic[TEventType]
an event that can be subscribed to and fired.
fire
fires the event
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event |
TEventType
|
the event to fire |
required |
continue_after_failure |
bool
|
True means to call all the callbacks even if one fails. False means to stop if one of the callbacks fails |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
True if all the callbacks succeeded, False otherwise |
subscribe
subscribes a callback to the event
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler |
Callable[[TEventType], None]
|
the callback to subscribe |
required |
StatefulListIterator
Bases: Collection[TItemType]
An list, that can be iterated from the last stopped location, in a circular fashion. every iteration starts from the last position iterated position, and iterates over all the list
ThreadLocalMember
Bases: Generic[TValueType]
this is a descriptor, for making thread local members for class:
class MyClass: x = ThreadLocalMember() y = ThreadLocalMember(1) z = ThreadLocalMember() w = ThreadLocalMember(1) def init(): self.x = 5 self.w = 2
a = MyClass(): a.x # 5 a.x = 7 # changes only for this thread a.y # 1 - the default init value for this a.z # raises AttributeError (z was not set on class). once it's set, then value is the init value for each thread a.w # 2 for this thread, 1 for any other thread (because of the default init value)
ThreadLocalValue
Bases: local, Generic[TValueType]
this class holds a single, thread-local value
x = ThreadLocalValue(5) x.value # 5 x.value = 7 # changes only for this thread
TimerContext
a context object that records how much time did the context last