circuits.core.events – Events — circuits 2.1.0 documentation

# circuits 2.1.0 documentation

# `circuits.core.events` – Events

This module defines the basic Event class and common events.

## Classes

class `circuits.core.events.` `Event`(*args, **kwargs)

  Bases: `circuits.core.events.BaseEvent`

  An Event is a message send to one or more channels. It is eventually dispatched to all components that have handlers for one of the channels and the event type.

  All normal arguments and keyword arguments passed to the constructor of an event are passed on to the handler. When declaring a handler, its argument list must therefore match the arguments used for creating the event.

  Every event has a `name` attribute that is used for matching the event with the handlers. By default, the name is the uncameled class name of the event.

  Variables: | channels – an optional attribute that may be set before firing the event. If defined (usually as a class variable), the attribute specifies the channels that the event should be delivered to as a tuple. This overrides the default behavior of sending the event to the firing component’s channel. When an event is fired, the value in this attribute is replaced for the instance with the channels that the event is actually sent to. This information may be used e.g. when the event is passed as a parameter to a handler. value – this is a `circuits.core.values.Value` object that holds the results returned by the handlers invoked for the event. success – if this optional attribute is set to `True`, an associated event `EventSuccess` (original name with “Success” appended) will automatically be fired when all handlers for the event have been invoked successfully. success_channels – the success event is, by default, delivered to same channels as the successfully dispatched event itself. This may be overridden by specifying an alternative list of destinations using this attribute. complete – if this optional attribute is set to `True`, an associated event `EventComplete` (original name with “Complete” appended) will automatically be fired when all handlers for the event and all events fired by these handlers (recursively) have been invoked successfully. success_channels – the complete event is, by default, delivered to same channels as the initially dispatched event itself. This may be overridden by specifying an alternative list of destinations using this attribute.

## Components

none

## Events

class `circuits.core.events.` `Error`(type, value, traceback, handler=None)

  Bases: `circuits.core.events.Event`

  Error Event

  This Event is sent for any exceptions that occur during the execution of an Event Handler that is not SystemExit or KeyboardInterrupt.

  Parameters: | type (type) – type of exception value (exceptions.TypeError) – exception object traceback (traceback) – traceback of exception kwargs (dict) – (Optional) Additional Information

class `circuits.core.events.` `Failure`(*args, **kwargs)

  Bases: `circuits.core.events.DerivedEvent`

  Failure Event

  This Event is sent when an error has occurred with the execution of an Event Handlers.

  Parameters: | event (Event) – The event that failed

class `circuits.core.events.` `Registered`(component, manager)

  Bases: `circuits.core.events.Event`

  Registered Event

  This Event is sent when a Component has registered with another Component or Manager. This Event is only sent iif the Component or Manager being registered with is not itself.

  Parameters: | component (Component) – The Component being registered manager (Component or Manager) – The Component or Manager being registered with

class `circuits.core.events.` `Signal`(signal, stack)

  Bases: `circuits.core.events.Event`

  Signal Event

  This Event is sent when a Component receives a signal.

  Parameters: | signal – The signal number received. stack – The interrupted stack frame.

class `circuits.core.events.` `Started`(component)

  Bases: `circuits.core.events.Event`

  Started Event

  This Event is sent when a Component has started running.

  Parameters: | component (Component or Manager) – The component that was started

class `circuits.core.events.` `Stopped`(component)

  Bases: `circuits.core.events.Event`

  Stopped Event

  This Event is sent when a Component has stopped running.

  Parameters: | component (Component or Manager) – The component that has stopped

class `circuits.core.events.` `Success`(*args, **kwargs)

  Bases: `circuits.core.events.DerivedEvent`

  Success Event

  This Event is sent when all handlers (for a particular event) have been executed successfully, see `Manager`.

  Parameters: | event (Event) – The event that has completed.

class `circuits.core.events.` `Unregister`(component=None)

  Bases: `circuits.core.events.Event`

  Unregister Event

  This Event ask for a Component to unregister from its Component or Manager.

class `circuits.core.events.` `Unregistered`(component, manager)

  Bases: `circuits.core.events.Event`

  Unregistered Event

  This Event is sent when a Component has been unregistered from its Component or Manager.

class `circuits.core.events.` `GenerateEvents`(lock, max_wait)

  Bases: `circuits.core.events.Event`

  Generate events event

  This event is sent by the circuits core. All components that generate timed events or events from external sources (e.g. data becoming available) should fire any pending events in their “generate_events” handler. The handler must either be a filter (preventing other handler from being called in the same iteration) or must invoke `reduce_time_left()` with parameter 0.

  Parameters: | max_wait – maximum time available for generating events.

  Components that actually consume time waiting for events to be generated, thus suspending normal execution, must provide a method `resume` that interrupts waiting for events.

  `time_left`

    The time left for generating events. A value less than 0 indicates unlimited time. You should have only one component in your system (usually a poller component) that spends up to “time left” until it generates an event.

  `reduce_time_left`(time_left)

    Update the time left for generating events. This is typically used by event generators that currently don’t want to generate an event but know that they will within a certain time. By reducing the time left, they make sure that they are reinvoked when the time for generating the event has come (at the latest).

    This method can only be used to reduce the time left. If the parameter is larger than the current value of time left, it is ignored.

    If the time left is reduced to 0 and the event is currently being handled, the handler’s resume method is invoked.

## Functions

none