Counter Callback implementation.

Callback that count events and calls the passed fn evert event_freq.


CounterCallback Count events of a specific type.
class ashpy.callbacks.counter_callback.CounterCallback(event, fn, name, event_freq=1)[source]

Bases: ashpy.callbacks.callback.Callback

Count events of a specific type. Calls fn passing the context every event_freq.

Useful for logging or for measuring performance. If you want to implement a callback defining a certain behaviour every n_events you can just inherit from CounterCallback.

__init__(event, fn, name, event_freq=1)[source]

Initialize the CounterCallback.

  • event ( – event to count.
  • fn (Callable) – function to call every event_freq events.
  • event_freq (int) – event frequency.
  • name (str) – name of the Callback.

ValueError – if event_freq is not valid.

on_event(event, context)[source]

Count events and calls fn.