Skip to main content

asyncio pydipatch (Signal Manager)

Project description

aio_pydispatch

GitHub Workflow Status (branch) GitHub PyPI codecov Codacy Badge

Asyncio pydispatch (Signal Manager)

This is based on pyDispatcher reference Django Signals and reference scrapy SignalManager implementation on Asyncio

Event or Signal (not python bif signal)

You can bind multiple listeners (called sender) to listening multiple handlers (called receiver) on one event (called signal).

Default, the listener is None, so when the event is fire with no listener, all handlers will be executed that was bind default listener.

Usage

Most of the program has start and stop events, we can register some handler to events, we can also specify a sender.

import asyncio

from aio_pydispatch import Signal

server_start = Signal()
server_stop = Signal()


def ppp(value: str, **kwargs) -> None:
    print(value, kwargs)


async def main():
    server_start.connect(ppp, sender='loading config')
    server_stop.connect(ppp)
    await server_start.send(sender='loading config', value='foo')
    await asyncio.sleep(1)
    await server_stop.send(value='foo')


if __name__ == '__main__':
    asyncio.run(main())

Similar design

sync:

async:

Others

Event system in Python

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

aio_pydispatch-1.0.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

aio_pydispatch-1.0.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file aio_pydispatch-1.0.0.tar.gz.

File metadata

  • Download URL: aio_pydispatch-1.0.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for aio_pydispatch-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e17a8654a106110f794e1d0b3e933f69458c9a21b8e937f4d7fa7bb77d6ee4e4
MD5 765a473a124ca55909e2e8decee99fa2
BLAKE2b-256 b635f5e38c30d6ada7baee214b851c4c347b619b0ddfc31ed88a4393a24d7b5c

See more details on using hashes here.

File details

Details for the file aio_pydispatch-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: aio_pydispatch-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for aio_pydispatch-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 771a7cedf976a869e6bede9bfa3655e64e86848abc810f5c353e9cfd83e03e9b
MD5 5352c26003c4185e9117071e3534083f
BLAKE2b-256 5a54a36932a6f1b404dba43d74ab9694e17fb24b91cecf2927f1d57dab4f9417

See more details on using hashes here.

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