python事件处理,c风格

axel的Python项目详细描述


axel是一个受c# 事件,允许轻松而优雅的事件处理。

示例:

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

功能:

- handlers can receive the sender as their first argument
- handlers can be executed in the same or 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 cached
- 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

贡献者:

Erwin Mayer <traderwin at gmail dot com>
Rob van der Most <Rob at rmsoft dot nl>

请参阅文档:https://pythonhosted.org/axel

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java我可以在J2EE1.4中使用JAXR吗   YouTube数据API超出了未经验证的java每日使用限制   java RED5 RTMPConnManager未设置applicationContext局部变量。这会导致NullPointerException   java多部分/formdata,加载图像(安卓)   java Struts 2<s:select>填充表单中的其他字段   java Eclipse在迁移后不会将邮件属性传递给Spring Boot   java如何检查请求的TLS版本   java如何从包中导入相同的类   如何在java中将BLOB字符串转换为人类可读的格式字符串   java使用Play映射特定的文件路径!框架   java Eclipse重构   在子字符串上使用“预定义字符类”的java   java如何在SeleniumWebDriver中选择li中的锚定标记?   jspjava。木卫一。FileNotFoundException:系统找不到指定的路径   java Hi,在启动cmd\design javafx\cmd eclipse时,我的文件不是删除的,也不是复制的   java Selenium Web驱动程序异常“找不到:taskkill的可执行文件”   java如何获得数组的迭代器?