# Class e.c.u.s.Signal(object):

Part of elisa.core.utils.signal View In Hierarchy

A Signal is a 1-to-many communication system. It provides a way for two objects to communicate without knowing about each other. They only have to know about the signal object. Receivers objects connect to the signal and emitters can trigger the emission of the signal so that it is sent to all the receivers. Signal emission is synchronous, that is, the receivers are immediatly called upon emission, one after the other.

WARNING:

- a Signal is *not* thread-safe
- the receivers are called in the emitting thread
- receivers calling is not ordered

TODO:

- might be useful to send a reference of the sender
- maybe add static extra data at connect time
- think about implementing return values support
- think about weak references for receivers http://docs.python.org/lib/module-weakref.html
- think about integrating it with Twisted and making signals deferred in threads

Line # | Kind | Name | Docs
--- | --- | --- | ---
84 | Method | __init__ | Initialize a signal with the signature of receivers that can connect
105 | Method | __repr__ | Textual representation of the Signal
114 | Method | connect | Connect a receiver to the signal. It will be called when the signal
134 | Method | disconnect | Disconnect a receiver from the signal.
149 | Method | emit | Call all the connected receivers. It avoids calling the

def __init__(self, name, *args_types, **kw_types):
Initialize a signal with the signature of receivers that can connect to it.

Parameters | name | name of the signal. Not unique, but developer friendly (type: string )
| args_types | arguments types of the receivers that can connect to the signal (type: tuple of types )
| kw_types | arguments types of the receivers that can connect to the signal (type: dictionary of types )

def __repr__(self):
Textual representation of the Signal

Returns | information about the signal and its receivers (type: string )

def connect(self, receiver, *args, **kw):
Connect a receiver to the signal. It will be called when the signal is emitted.

Parameters | receiver | object to be called when the signal is emitted (type: callable )
| params | parameters to send to the receiver when calling
| kw | keywords to send to the receiver when calling
Unknown Field: exception | TypeError | raised if the receiver is not callable

def disconnect(self, receiver):
Disconnect a receiver from the signal.

Parameters | receiver | object to be disconnected (type: callable )
Raises | IndexError | raised if the receiver is not in the list of receivers

def emit(self, *args, **kw):
Call all the connected receivers. It avoids calling the neutralized ones. Since receivers calling is not ordered, one should be careful with the potential side effects in the receivers.

Parameters | args | arguments passed to the receivers (type: tuple )
| kw | arguments passed to the receivers (type: dictionary )
Unknown Field: exception | WrongArgument | Raised if one of the arguments is of the wrong type