def remove(weak, self=self):
            """Set self.isDead to true when method or instance is destroyed"""
            methods = self.deletionMethods[:]
            del self.deletionMethods[:]
            try:
                del self.__class__._allInstances[ self.key ]
            except KeyError:
                pass
            for function in methods:
                try:
                    if hasattr(function, '__call__' ):
                        function( self )
                except Exception as e:
                    try:
                        traceback.print_exc()
                    except AttributeError:
                        print('''Exception during saferef %s cleanup function %s: %s'''%(
                            self, function, e
                        ))
Set self.isDead to true when method or instance is destroyed
stackoverflow/venv/lib/python3.6/site-packages/pydispatch/saferef.py