From: Mike C. F. <mcf...@ro...> - 2003-08-13 11:07:56
|
Thomas Heller wrote: >"Mike C. Fletcher" <mcf...@ro...> writes: > > ... >>class Holder( object ): >> def __init__( self, method, client ): >> self.method= method # strong reference, kept alive >> self.client = saferef.safeRef( client, onDelete = self.cleanup ) >> >> ... >Mike, thanks for this suggestion. It didn't work exactly as shown above, >but it showed me the way to do it. I assume you meant > self.client = weakref.ref(client, self.cleanup) >instead of > self.client = saferef.safeRef( client, onDelete = self.cleanup ) >or did I miss something. > Probably that I'm using the latest version of pydispatcher (the package) from sourceforge. It splits out the various pieces of functionality into seperate reusable modules, so that there's a saferef module which does all the "safe reference to a method" stuff from the dispatcher module. That way if the client object is itself a method of an object it won't just disappear when the function that accessed it exits. There's also a robustapply module which does all the "figure out which arguments apply to this callable object and call it with that subset of the passed arguments" stuff. The dispatcher module itself also has a few new convenience functions: def getAllReceivers( sender = Any, signal = Any ): """Get list of all receivers from global tables def liveReceivers(receivers): """Filter sequence of receivers to get resolved, live receivers def sendExact( signal=Any, sender=Anonymous, *arguments, **named ): """Send signal only to those receivers registered for exact message def getReceivers( sender = Any, signal = Any ): """Get list of receivers from global tables >And sorry for the late reply. > No problem, I'm far too busy these days myself. Glass houses and stones and all :) . Have fun, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |