pubsub.py issues?

From: Roger Binns [mailto:rogerb@rogerbinns.com]

Robb Shecter wrote:
> I'm going through the pubsub.py module - writing test cases and ironing

out

> any bugs. I wrote the original posters of a thread about the module,

but if

> anyone else has any issues with it, please let me know.

The biggest problem is that the current version doesn't allow the objects
of bound methods to be garbage collected. You can manually work around
that by having your own layer on top, as I have posted about on this
list before.

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.

My version uses weak references. I'm still doing tests on it. Unfortunately,
the standard weakref module doesn't give (IMO) good support for bound
methods, as weakly bound methods are dead on arrival, which means you have
to do special gymnastics to keep them alive. Anyways so far the tests are
positive.

The _makeCallable/_parameterCount stuff is also overly complex and
should be removed IMHO. For example it prevents passing in objects with
a __call__ method. (Just always provide the message).

That's what I ended up doing, so the version I have supports functions,
bound methods and callable instances. It requires a function to have at
least one parameter, which is a minus compared to the old pubsub, if that is
a feature you were relying on.

The implementation also prevents usage in a multi-threading environment
(or more accurately in more than one thread). I don't have a prescribed
solution for that.

I haven't addressed that issue. Possibly could look at it, but might need
some help there.

If Robb doesn't object, and if others are interested, I can make the code
available in the next week.

Oliver

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/

Have fun,
Mike

ยทยทยท

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