本文整理汇总了Python中tenacity.before_log方法的典型用法代码示例。如果您正苦于以下问题:Python tenacity.before_log方法的具体用法?Python tenacity.before_log怎么用?Python tenacity.before_log使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tenacity
的用法示例。
在下文中一共展示了tenacity.before_log方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quota_retry
# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import before_log [as 别名]
def quota_retry(*args, **kwargs) -> Callable:
"""
A decorator that provides a mechanism to repeat requests in response to exceeding a temporary quote
limit.
"""
def decorator(fun: Callable):
default_kwargs = {
'wait': tenacity.wait_exponential(multiplier=1, max=100),
'retry': retry_if_temporary_quota(),
'before': tenacity.before_log(log, logging.DEBUG),
'after': tenacity.after_log(log, logging.DEBUG),
}
default_kwargs.update(**kwargs)
return tenacity.retry(
*args, **default_kwargs
)(fun)
return decorator
示例2: operation_in_progress_retry
# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import before_log [as 别名]
def operation_in_progress_retry(*args, **kwargs) -> Callable:
"""
A decorator that provides a mechanism to repeat requests in response to
operation in progress (HTTP 409)
limit.
"""
def decorator(fun: Callable):
default_kwargs = {
'wait': tenacity.wait_exponential(multiplier=1, max=300),
'retry': retry_if_operation_in_progress(),
'before': tenacity.before_log(log, logging.DEBUG),
'after': tenacity.after_log(log, logging.DEBUG),
}
default_kwargs.update(**kwargs)
return tenacity.retry(
*args, **default_kwargs
)(fun)
return decorator