def safeRef(object):
    """Return a *safe* weak reference to a callable object."""
    if hasattr(object, 'im_self'):
        if object.im_self is not None:
            # Turn a bound method into a BoundMethodWeakref instance.
            # Keep track of these instances for lookup by disconnect().
            selfkey = object.im_self
            funckey = object.im_func
            if not _boundMethods.has_key(selfkey):
                _boundMethods[selfkey] = weakref.WeakKeyDictionary()
            if not _boundMethods[selfkey].has_key(funckey):
                _boundMethods[selfkey][funckey] = \
                BoundMethodWeakref(boundMethod=object)
            return _boundMethods[selfkey][funckey]
    return weakref.ref(object, _removeReceiver)
Return a *safe* weak reference to a callable object.
recipes/Python/87056_Global_Signal_Dispatching/recipe-87056.py