msignal Module

msignal.py This module contains classes and functions for the signal sending/receiving system.

The Signal system implements a kind of slot-filler, subscriber-receiver model, so that we can have many-to-many signal sending without senders needing to know about recipients.

Here’s how it works:

A SignalDispatcher object is the central manager of all signals incoming and outgoing.

Arbitrary objects can register (with the dispatcher) in order to broadcast signals (they send them to the dispatcher);
note that registering in this case does little – ATTN:TODO add more about why to do this?

Arbitrary objects can register (with the dispatcher) in order to subscribe to receive signals matching certain criteria.

To receive messages, one creates a SignalReceiver object (essentially a wrapper) which specifies a callback function,
a filter to define which singals to send, and additional parameters to pass to the callback function.
To broadcast a signal message, one simply calls the dispatcher broadcast function and provides:
  • id - a dotted path string representing the signal’s name; the most common scenario will be when receivers match on exact signal message names.
  • message - arbitrary object representing the message contents; convention will dictate the type and contents.
  • request - reference to the current request being processed (useful to have for various things like logging)
  • source - a dotted path string representing the signal’s “source”; convention may dictate use; can be useful as another field for filtering by recipients.
  • flag_collectresults - if True then a list collecting the the return values from the recipients will be returned; list is of tuples (returnval, failure)

There are some details of importance:

  • Rather than use a strict interface-signature typing to ensure that signals are parameterized correctly.
  • Instead, we use a very generic approach to signal formats; this makes things simpler and easier
  • But this puts more burden on subscribers to be careful processing passed signal parameters
  • We favor simplicity and avoid magic stuff that happens automatically; we do not auto-register signals.
  • The closest similar python implementation can be found in Django signals
  • We want to be as efficient as possible when we can be.

ATTN:TODO - There is a lot more to implement here.

class mewlo.mpacks.core.signal.msignal.MewloSignalManager(mewlosite, debugmode)[source]

Bases: mewlo.mpacks.core.manager.manager.MewloManager

The signal dispatcher.

broadcast(id, message, request, source, flag_collectresults=False)[source]

An object calls this function whenever it wants to broadcast a signal to all listeners. :id: Dotted string representing signal name :message: The signal message contents (could be a string or any arbitrary object; common case would be to pass a dictionary); convention dictates use :source: None | Dictionary described “source” of message, which can be used to filter by receivers; convention dictates use :flag_collectresults: If True, then the results from every called receiver will be collected and returned as a list of tuples

description = 'The Signal Manager is a central place where signals can be sent and objects can register to receive notices about them'
dumps(indent=0)[source]

Debug information.

register_receiver(receiver)[source]

This function is called ONCE by a component that wishes to received signals (of a certain kind and/or by a certain sender). This is currently the only one of the register functions that we bother with; the others are not important.

register_sender(sender)[source]

This function is called ONCE by a component that it might send/broadcast signals. ATTN: for now we don’t use this

register_signal(signal)[source]

This function is called ONCE by a component to describe/advertise a kind of signal that it might send. This function serves to aid documentation – it simply provides information that we could use to keep track of potential signals. It may also provide meta information to potential listeners. ATTN: for now we don’t use this

shutdown()[source]
shutdown_obj_ifownedby(obj, owner)[source]

If a component has the owner specified, shut it down and return True; otherwise return False.

startup(eventlist)[source]
typestr = 'core'
unregister_all()[source]

Shutdown all registered receivers.

unregister_byowner(owner)[source]

Unregister anything owned by the specified ownerobject.

class mewlo.mpacks.core.signal.msignal.MewloSignalReceiver(owner, callback, idfilter, sourcefilter, extra=None, flag_returnsvalue=True)[source]

Bases: object

The object receives signals from dispatcher.

does_want_signal(id, message, request, source)[source]
dumps(indent=0)[source]

Debug information.

handle_signal(id, message, request, source, flag_collectresults)[source]
The receiver MUST receive a call of the form:
  • callback(thisSignalReceiver, id, message, source)

The self.flag_returnsvalue tells us whether we should expect the callback to return a tuple of (result,failure) format For the format of id, message, source, see broadcast() function below. The thisSignalReceiver reference points to the receiver that was registered to receive the signal; it can be used to maintain and look up arbitrary data.

startup(mewlosite, eventlist)[source]
class mewlo.mpacks.core.signal.msignal.SignalSender[source]

Bases: object

The object that sends signals to the receiver.

dumps(indent=0)[source]

Debug information.

startup(mewlosite, eventlist)[source]

Table Of Contents

This Page