devices.py 文件源码

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

项目:device-updater 作者: spark 项目源码 文件源码
def try_with_timeout(target, args, timeout, pause):
    """
    Attempt an operation as long as it fails up to the given timeout.
    :param target:  The callable
    :param args:    The arguments to pass
    :param timeout: the timeout
    :param pause:   how long to pause between each failed invocation
    :return: either the result from successfully invoking the callable
    raises the exception thrown by the callable on timeout.
    """
    end = time.perf_counter()+timeout
    result, exception = try_invoke(target, args)
    while exception is not None and time.perf_counter()<end:
        time.sleep(pause)
        result, exception = try_invoke(target, args)
    if exception is not None:
        raise exception
    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号