Skip to main content

Python events handling

Project description

Axel is a very small Python library for events handling.

Examples:

from axel import Event

event = Event()
def on_event(*args, **kwargs):
    return (args, kwargs)

event += on_event                     #handler registration
print(event(10, 20, y=30))
>> ((True, ((10, 20), {'y': 30}), <function on_event at 0x00BAA270>),)

event -= on_event                     #handler is unregistered
print(event(10, 20, y=30))
>> None


class Mouse(object):
    def __init__(self):
        self.click = Event(self)
        self.click += self.on_click   #handler registration

    def on_click(self, sender, *args, **kwargs):
        assert isinstance(sender, Mouse), 'Wrong sender'
        return (args, kwargs)

mouse = Mouse()
print(mouse.click(10, 20))
>> ((True, ((10, 20), {}),
>>  <bound method Mouse.on_click of <__main__.Mouse object at ...>>),)

mouse.click -= mouse.on_click         #handler is unregistered
print(mouse.click(10, 20))
>> None

Features:

- handlers can receive the sender as their first argument
- handlers are always executed in separate threads
- handlers may be executed synchronous or asynchronous
- handlers execution may be synchronized on a lock
- the time allocated for the execution of a handler is controllable
- the number of actively executed handlers at one time is controllable
- the execution result of a handler can be memoized
- the result of the execution is provided as a tuple ((flag, result, handler),)
- in case of error, the traceback may be provided for each handler in error

Please see the documentation: https://pythonhosted.org/axel

Latest versions available on Github, they will be deployed on pypi on version change

https://github.com/axel-events/axel

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

axel-src-0.0.5.zip (19.3 kB view details)

Uploaded Source

File details

Details for the file axel-src-0.0.5.zip.

File metadata

  • Download URL: axel-src-0.0.5.zip
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for axel-src-0.0.5.zip
Algorithm Hash digest
SHA256 c3debe70842182493b0399eb62634686d0a0ca7982402cad37a68a225710e018
MD5 3384389c8aec1af9cfe784a16d3de451
BLAKE2b-256 b00d556c3b32d22a1b94fa84a3847e7fab651d632dd968fe169ccc68bf2bf3ae

See more details on using hashes here.

Supported by

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