Python 金字塔中请求外部的自定义事件

Python 金字塔中请求外部的自定义事件,python,pyramid,Python,Pyramid,我试图在我的应用程序的\uuuu init\uuu方法中通知我的自定义事件,并在应用程序的包含部分捕获/订阅它。但由于某些原因,导入代码中的订阅服务器未被调用。如果在相同的导入代码中,我订阅了金字塔事件,那么一切都正常。下面是代码示例 \uuuu init\uuuuu.py class MyEvent(object): pass def main(...): ... config.include('some_module') config.registry.notify(My

我试图在我的应用程序的
\uuuu init\uuu
方法中通知我的自定义事件,并在应用程序的包含部分捕获/订阅它。但由于某些原因,导入代码中的订阅服务器未被调用。如果在相同的导入代码中,我订阅了金字塔事件,那么一切都正常。下面是代码示例

\uuuu init\uuuuu.py

class MyEvent(object): pass

def main(...):
   ...
   config.include('some_module')
   config.registry.notify(MyEvent())
   ...
def handle_event(e):
  print 'event', e

def includeme(config):
  print 'module included'
  config.add_subscriber(handle_event, 'myapp.MyEvent')
some_module.py

class MyEvent(object): pass

def main(...):
   ...
   config.include('some_module')
   config.registry.notify(MyEvent())
   ...
def handle_event(e):
  print 'event', e

def includeme(config):
  print 'module included'
  config.add_subscriber(handle_event, 'myapp.MyEvent')

打印包含的行
模块
,但不打印
事件
行。这就是金字塔中通知/订阅的工作原理吗?代码中有错误吗?谢谢在
config.include()
之后,您必须使用
config.commit()
显式提交
配置程序,然后才能将
config.add\u订阅服务器(…)
添加到内部注册表以供使用

换句话说,当前当您调用
.notify(…)
时,尚未注册事件的订户