pipert.core.routine¶
Module Contents¶
Classes¶
Events that are fired by the |
|
An object that is used to pass internal and user-defined state between |
|
Every routine will have a type |
|
Helper class that provides a standard way to create an ABC using |
-
class
pipert.core.routine.Events[source]¶ Bases:
enum.EnumEvents that are fired by the
RoutineInterfaceduring execution.
-
class
pipert.core.routine.State[source]¶ Bases:
objectAn object that is used to pass internal and user-defined state between event handlers.
-
class
pipert.core.routine.Routine(logger, name='', component_name='', extensions=None, metrics_collector=NullCollector(), *args, **kwargs)[source]¶ Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
-
register_events(self, *event_names)[source]¶ Add events that can be fired.
Registering an event will let the user fire these events at any point. This opens the door to make the
run()loop even more configurable.By default, the events from
Eventsare registerd.- Args:
- *event_names: An object (ideally a string or int) to define the
name of the event being supported.
Example usage:
from enum import Enum class Custom_Events(Enum): FOO_EVENT = "foo_event" BAR_EVENT = "bar_event" routine = Routine(process_function) routine.register_events(*Custom_Events)
-
add_event_handler(self, event_name, handler, first=False, last=False, *args, **kwargs)[source]¶ Add an event handler to be executed when the specified event is fired.
- Args:
event_name: An event to attach the handler to. Valid events are from
Eventsor any event_name added byregister_events().handler (callable): the callable event handler that should be invoked first: specify ‘true’ if the event handler should be called first last: specify ‘true’ if the event handler should be called last *args: additional args to be passed to handler. **kwargs: additional keyword args to be passed to handler.
- Notes:
The handler function’s first argument will be self, the
Routineobject it was bound to.Note that other arguments can be passed to the handler in addition to the *args and **kwargs passed here, for example
during
EXCEPTION_RAISED.
Example usage:
routine = Routine(process_function) def print_epoch(routine): print("Epoch: {}".format(routine.state.epoch)) routine.add_event_handler(Events.EPOCH_COMPLETED, print_epoch)
-
has_event_handler(self, handler, event_name=None)[source]¶ Check if the specified event has the specified handler.
- Args:
handler (callable): the callable event handler. event_name: The event the handler attached to. Set this
to
Noneto search all events.
-
remove_event_handler(self, handler, event_name)[source]¶ Remove event handler handler from registered handlers of the routine
- Args:
handler (callable): the callable event handler that should be removed event_name: The event the handler attached to.
-
_extension_log_fps(self, fps_time_interval)[source]¶ Log the fps of routine every fps_time_interval seconds
- Args:
fps_time_interval: Interval time between each log.
-
_extension_pace(self, fps)[source]¶ Pace the routine to work at a wanted fps
- Args:
fps: The wanted fps for the routine
-
_fire_event(self, event_name, *event_args, **event_kwargs)[source]¶ Execute all the handlers associated with given event.
This method executes all handlers associated with the event event_name. Optional positional and keyword arguments can be used to pass arguments to all handlers added with this event. These aguments updates arguments passed using
add_event_handler().
-
abstract static
get_constructor_parameters()[source]¶ Returns a dictionary of the constructor’s parameters built as key for name and value for type name
-