code: def monitor_deletion():
      
      monitors = {}
  
      def set_deleted(x):
          def _(weakref):
              del monitors[x]
          return _
  
      def monitor(item, name):
          monitors[name] = ref(item, set_deleted(name))
  
      def is_alive(name):
          return monitors.get(name, None) is not None
  
      return monitor, is_alive
docs: Function for checking for correct deletion of weakref-able objects.
  
      Example usage::
  
          monitor, is_alive = monitor_deletion()
          obj = set()
          monitor(obj, "obj")
          assert is_alive("obj") # True because there is a ref to `obj` is_alive
          del obj
          assert not is_alive("obj") # True because there `obj` is deleted