Skip to main content

Overview

This library exposes a mechanism for signalling in Python. Through this mechanism you can create a Signal class and then connect that signal to any number of callable end points. Upon that signal being emitted the Signal class will then trigger a call to all the connected callables.

This pattern allows for events to be propagated to different classes/functions when they occur.

Install

pip install signalling

Example

This example shows how to use a basic signal:

import signalling

# -- Declare some functions. This can be functions, methods
# -- or classsmethods
def do_something():
    print("doing something")

def do_something_else():
    print("doing something else")

# -- Create a singal
signal = signalling.Signal()

# -- Connect the signal to various end points
signal.connect(do_something)
signal.connect(do_something_else)

# -- Now we can emit the signal and all the end
# -- points will be called (in order they were
# -- connected)
signal.emit()

WeakSignal

The standard Signal class will hold a direct reference to the callable its connected to. This means the endpoint will never be garbage collected whilst the signal is alive.

However, there are times that we want to use the signalling mechanism but we dont want to hold a direct reference. For this we can use signalling.WeakSignal. This version of the signalling class will only hold a weak reference to the callable end point, so it allows for the garbage collecting of end points if nothing else is holding a reference to it outside of the Signal class.

The approach to using the WeakSignal is exactly the same, and all the weakref management is carried out by the signal class itself.

import signalling

# -- Declare some functions. This can be functions, methods
# -- or classsmethods
def do_something():
    print("doing something")

def do_something_else():
    print("doing something else")

# -- Create a singal
signal = signalling.WeakSignal()

# -- Connect the signal to various end points
signal.connect(do_something)
signal.connect(do_something_else)

# -- Now we can emit the signal and all the end
# -- points will be called (in order they were
# -- connected)
signal.emit()

Metadata

Release files for signalling 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for signalling 1.0.1
File Size Uploaded
signalling-1.0.1.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for signalling 1.0.1
File Interpreter ABI Platform
signalling-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / signalling-1.0.1.tar.gz

Download URL signalling-1.0.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ae9fda8d9ca0199935ef4c245f07c04a06f0cca64d3b9269c874cf0bd4f04874
BLAKE2b-256 checksum
How to use checksums
75c085ee081a6d3134afa76929ab34eac075f519e7536ecbe8a9cdc4969876a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / signalling-1.0.1-py3-none-any.whl

Download URL signalling-1.0.1-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
937331b4944f09d0c2b83cf4f0abd3d633e84b06baac6a3e69c72763d0c9a6a6
BLAKE2b-256 checksum
How to use checksums
fb0ac8be17d3cf41aadfae50aa0a71389655f357e6e75d0c3914e309c97b16f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page