pubsub.py issues?

From: Mike C. Fletcher [mailto:mcfletch@rogers.com]

Schoenborn, Oliver wrote:

>Yes, that was a real problem for me so I have implemented my own version

of

>pubsub, based on Robb's. There is actually very little of the original

code

>left, but Robb's pubsub certainly provided a solid base from which to

start,

>thanks Robb for that.
>
PyDispatcher has a "saferef" module which might be of interest, it
deconstructs method references into weakrefs to both object and function
so that either one going away will eliminate the callback. It's been
used quite extensively (the recipe before it especially so), and save
for actual bugs in the Python interpreter's weakref handling (all of
which appear to be fixed in Python 2.3.3) should be fairly reliable.

http://pydispatcher.sourceforge.net/

Thanks Mike, PyDispatcher looks great. Do you bother keeping a save ref to
the function for the method, or just the object to which the method belongs?
Interesting idea, I guess this way you cover the case of something deleting
a function from a class.

One feature that I like with pubsub is the concept of 'topics' and,
especially, the hierarchical nature of topics as supported by pubsub.

Oliver

Schoenborn, Oliver wrote:

From: Mike C. Fletcher [mailto:mcfletch@rogers.com]

Schoenborn, Oliver wrote:
   

...

Thanks Mike, PyDispatcher looks great. Do you bother keeping a save ref to
the function for the method, or just the object to which the method belongs?
Interesting idea, I guess this way you cover the case of something deleting
a function from a class.

Yes, we store two weakrefs per instance-method ref. It does allow for deleting the functions, changing their names in the class definition, etceteras, but mostly it's motivated by simplicity and robustness, since you already have the function lookup done (and the lookup could be complex if someone's playing around with meta-features) in the instance-method, there's no reason to re-acquire it by a fragile reduction to a name/string and then re-acquisition when you want the function object in the end anyway.

One feature that I like with pubsub is the concept of 'topics' and,
especially, the hierarchical nature of topics as supported by pubsub.

I can see how such a thing might be interesting, but can you give a concrete use-case example for it? I'm guessing something like "capture all 'mouse' events" versus "capture 'mouse-down' events"? Might be useful add-on for PyDispatcher (which, btw, is Patrick's creation, I just helped with packaging it up). Would have to give some thought as to the restrictions that it would place on the "signal" object before implementing it as default, though.

It would be quite easy to do something such that sending a string signal of 'mouse.down' would sendExact a mouse.down, and if it got no results, sendExact a 'mouse' signal, and if that failed send generic messages (that last would need to be factored into a reusable function I suppose, it's wrapped up in the send function now)... But then you're stuck with the constrained signal types... still, only if you rely on that particular send function, so no biggie.

Ah, if only there were time to work on the interesting projects,
Mike

ยทยทยท

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/