def METHOD_NAME(weak, self=self):
    """Set self.isDead to True when method or instance is destroyed."""
    methods = self.deletion_methods[:]
    del self.deletion_methods[:]
    try:
        del self.__class__._all_instances[self.key]
    except KeyError:
        pass
    for function in methods:
        try:
            if isinstance(function, collections.abc.Callable):
                function(self)
        except Exception:
            try:
                traceback.print_exc()
            except AttributeError as e:
                print(
                    (
                        "Exception during saferef %s "
                        "cleanup function %s: %s" % (self, function, e)
                    )
                )