List Info

Thread: Re: Web Site Process Bus




Re: Web Site Process Bus
country flaguser name
United States
2007-06-25 16:46:48
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 | ianbcolorstudy.com | http://blog.ianbicking.org

             | Write code, do good | http://topp.openpla
ns.org/careers
_______________________________________________
Web-SIG mailing list
Web-SIGpython.org
Web SIG: http://www.python.
org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/bo
nd%40yahoo.com

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )