exceptions.py 文件源码

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

项目:presto-python-client 作者: prestodb 项目源码 文件源码
def retry_with(handle_retry, exceptions, conditions, max_attempts):
    def wrapper(func):
        @functools.wraps(func)
        def decorated(*args, **kwargs):
            error = None
            result = None
            for attempt in range(1, max_attempts + 1):
                try:
                    result = func(*args, **kwargs)
                    if any(guard(result) for guard in conditions):
                        handle_retry.retry(func, args, kwargs, None, attempt)
                        continue
                    return result
                except Exception as err:
                    error = err
                    if any(isinstance(err, exc) for exc in exceptions):
                        handle_retry.retry(func, args, kwargs, err, attempt)
                        continue
                    break
            logger.info('failed after {} attempts'.format(attempt))
            if error is not None:
                raise error
            return result
        return decorated
    return wrapper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号