aio.signals-0.1.3
توضیحات
Pubsub system for aio framework
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | aio.signals-0.1.3 |
| نام | aio.signals |
| نسخه کتابخانه | 0.1.3 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Ryan Northey |
| ایمیل نویسنده | ryan@3ca.org.uk |
| آدرس صفحه اصلی | http://github.com/phlax/aio.signals |
| آدرس اینترنتی | https://pypi.org/project/aio.signals/ |
| مجوز | GPL |
Detailed documentation
**********************
aio.signals
===========
Pubsub system for the aio_ asyncio framework
.. _aio: https://github.com/phlax/aio
Build status
------------
.. image:: https://travis-ci.org/phlax/aio.signals.svg?branch=master
:target: https://travis-ci.org/phlax/aio.signals
Installation
------------
Requires python >= 3.4
Install with:
.. code:: bash
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
.. code:: python
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
.. code:: bash
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!
نحوه نصب
نصب پکیج whl aio.signals-0.1.3:
pip install aio.signals-0.1.3.whl
نصب پکیج tar.gz aio.signals-0.1.3:
pip install aio.signals-0.1.3.tar.gz