utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:kube-aws-flocker 作者: wallnerryan 项目源码 文件源码
def loop_until(predicate, timeout=None, message="task"):
    """
    Call predicate every second, until it returns something ``Truthy``.

    :param predicate: Callable returning termination condition.
    :type predicate: 0-argument callable returning a Deferred.

    :return: A ``Deferred`` firing with the first ``Truthy`` response from
        ``predicate``, or, if predicate didn't fire truthfully within the
        timeout, raise TimeoutError().
    """
    d = maybeDeferred(predicate)
    then = time.time()
    def loop(result):
        if timeout and time.time() - then > timeout:
            raise TimeoutError()
        if not result:
            print "Retrying %s given result %r..." % (message, result)
            d = deferLater(reactor, 1.0, predicate)
            d.addCallback(loop)
            return d
        return result
    d.addCallback(loop)
    return d
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号