0

我有一个用@retry 装饰的函数(来自重试库),如果这是重试,我想改变函数的行为以记录更多信息 - 是否有内置的方法来处理这个?

即是这样的:

from retrying import retry

@retry
def foo():
    if retry:
        log('retrying')
    throw Exception

4

1 回答 1

0

This library is not updated. You can use tenacity.

doc: https://tenacity.readthedocs.io/en/latest/

You can log before or after

import logging

logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

logger = logging.getLogger(__name__)

@retry(stop=stop_after_attempt(3), before=before_log(logger, logging.DEBUG))
def raise_my_exception():
    raise MyException("Fail")
于 2020-02-21T10:58:31.867 回答