'Build a cleanup clojure that doesn\'t increase our ref count'

def _cleanup_factory(self):

    _self = weakref.proxy(self)
    def wrapper():
        try:
            _self.close(timeout=0)
        except (ReferenceError, AttributeError):
            pass
    return wrapper
