code: def _cleanup_factory(self):
          
          _self = weakref.proxy(self)
          def wrapper():
              try:
                  _self.close(timeout=0)
              except (ReferenceError, AttributeError):
                  pass
          return wrapper
docs: Build a cleanup clojure that doesn't increase our ref count