[Web-SIG] Web Site Process Bus

Ian Bicking ianb at colorstudy.com
Mon Jun 25 23:46:48 CEST 2007


Ian Bicking wrote:
> Phillip J. Eby wrote:
>> 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)
> 
> I don't think that makes sense for this case.  The way I imagine using 
> it is:
> 
> class MyApplication(object):
> 
>      def __init__(self, db):
>          self.db = db
>          subscribe('reload_resources', self.reload)
>      def reload(self, data=None):
>          self.db.close()
>          self.db.open()
> 
> That is, I subscribe one particular thing when it is applicable, not 
> because the library is on the system.

I forgot to add: this makes me think that some sort of weakref handling 
would be nice, because in this case I won't want the application to 
persist just because it's listening to this signal.

-- 
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
             | Write code, do good | http://topp.openplans.org/careers


More information about the Web-SIG mailing list