我试图在应用程序的__init__
方法中通知我的自定义事件,并在应用程序的包含部分捕获它/订阅它。但由于某些原因,导入代码中的订户没有被调用。如果在同一个导入的代码中,我订阅了金字塔事件,那么一切都正常。下面是代码示例。你知道吗
\uuu init\uuuuuuuuuy.py
class MyEvent(object): pass
def main(...):
...
config.include('some_module')
config.registry.notify(MyEvent())
...
一些_模块.py
def handle_event(e):
print 'event', e
def includeme(config):
print 'module included'
config.add_subscriber(handle_event, 'myapp.MyEvent')
打印行module included
,但不打印event
行。金字塔中的通知/订阅就是这样工作的吗?代码中有错误吗?谢谢
在
config.include()
之后,必须使用config.commit()
显式提交Configurator
,然后config.add_subscriber(...)
才能添加到内部注册表中使用。你知道吗换句话说,当前当您调用
.notify(...)
时,还没有注册事件的订户。你知道吗相关问题 更多 >
编程相关推荐