Skip to main content

Simple signal/slot implementation

Project description

What is this?

signaling is a simple implementation of the signal/slot pattern as known from the Qt framework. It has no external requirements and 100% test-coverage.


The usual

pip install signaling

How to use it?

Consider that you have a function that should be called whenever a connected signal is emitted, as illustrated by the following code block:

def slot(arg):
  print("Slot called with {}".format(arg))

signal = Signal(args=['arg'])
signal.emit(arg=1)  # Slot called with 1

In fact you can connect multiple slots to the same signal, as long as they share the same function signature.

Notice that the signaling library performs some sanity checks when connecting slots and emitting signals.

  • All slots connected to a signal have to provide the same argument specifiction as denoted by the args parameter of the Signal constructor.

  • An emit-call has to be made with the exact same arguments as specified with the Signal constructor.

So all of the below examples would raise an exception:

def slot_with_arg(arg):

def slot_without_arg():

# InvalidSlot: Slot 'slot_with_arg' has to callable without arguments

# InvalidSlot: Slot 'slot_without_args' has to accept args ['arg'] or **kwargs.

s = Signal()
# InvalidEmit: Emit has to be called without arguments.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

signaling-1.0.0.tar.gz (11.9 kB view hashes)

Uploaded Source

Built Distribution

signaling-1.0.0-py2.py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page