Skip to main content

aio.signals

Pubsub system for the aio asyncio framework

Build status

https://travis-ci.org/phlax/aio.signals.svg?branch=master

Installation

Requires python >= 3.4

Install with:

pip install aio.signals

Quickstart

The listen function is called synchronously, but the callback listener will be called as a coroutine if it isnt one

The callback listener receives a signal object that has the name of the signal and the object that the signal was emitted with

The emit function is a coroutine

Add the following code to a file my_signals.py

import asyncio
from aio.signals import Signals

def listener(signal):
    yield from asyncio.sleep(1)
    print(signal.data)

signals = Signals()
signals.listen("my-signal", listener)

loop = asyncio.get_event_loop()
loop.run_until_complete(
    signals.emit("my-signal", 'BOOM!'))

Run with

python my_signals.py

aio.signals usage

Using

>>> import asyncio
>>> import aio.testing
>>> from aio.signals import Signals

The handler receives a signal object

signal.name is the name of the signal

signal.data contains the emitted object

>>> @asyncio.coroutine
... def callback(signal):
...     print("%s received with %s" % (signal.name, signal.data))
>>> @aio.testing.run_until_complete
... def run_test(_signals, name, message):
...     yield from _signals.emit(name, message)
>>> signals = Signals()
>>> signals.listen("test-signal", callback)
>>> run_test(signals, "test-signal", 'BOOM!')
test-signal received with BOOM!

The handler is wrapped in a co-routine if its not one already

>>> def callback(signal):
...     yield from asyncio.sleep(1)
...     print("%s received with %s" % (signal.name, signal.data))
>>> signals = Signals()
>>> signals.listen("test-signal-2", callback)
>>> run_test(signals, "test-signal-2", 'BOOM AGAIN!')
test-signal-2 received with BOOM AGAIN!

Release files for aio.signals 0.1.3

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

Source distribution (sdist)

Source distribution for aio.signals 0.1.3
File Size Uploaded
aio.signals-0.1.3.tar.gz 3.6 kB Details

Release files / aio.signals-0.1.3.tar.gz

Download URL aio.signals-0.1.3.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
be89f70c96ae300354518fc08672cc37c36c166b1a2167b5b8d1d591a81d4342
BLAKE2b-256 checksum
How to use checksums
41a06b45b50f6c5b4629bd6e458e26b8dad66787c34487e3cf083de84511371c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.3 This release

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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