[Web-SIG] Web Site Process Bus
Phillip J. Eby
pje at telecommunity.com
Mon Jun 25 22:18:05 CEST 2007
At 02:28 PM 6/25/2007 -0500, Ian Bicking wrote:
>Potentially a Zope-style minimal event framework would work. Maybe
>something like:
>
> send_signal(signal_name, signal_data)
> subscribe(signal_name, listener)
That was what I was wondering, too, except I was thinking it would be
sufficient to use entry points for subscription, but only invoke the
entry points whose modules are in sys.modules. In other words, never
actually import a module in order to invoke a callback. That way,
subscription is a natural side effect of importing the modules that
contain the listeners. Something like:
def send_signal(group, name, *args, **kw):
for ep in iter_entry_points(group, name):
if ep.module_name in sys.modules:
ep.load()(*args, **kw)
would then be sufficient. pkg_resources is currently proposed for
inclusion in Python 2.6 (per PEP 365), so there wouldn't even be any
non-stdlib requirements then. And of course the implementation is
trivial enough to copy into any code that wants to send signals.
Of course, if you want prioritized callbacks, you can always sort the
ep.load() results using a priority attribute or some such. I'm not
sure priority makes much sense, though, due to the difficulty of
determining a global priority scheme.
More information about the Web-SIG
mailing list