首页 > 解决方案 > 重试时的Python Tenacity日志异常

问题描述

我正在使用该tenacity包重试一个功能。我的重试装饰器如下所示:

@retry(wait=wait_exponential(multiplier=1/(2**5), max=60), after=after_log(logger, logging.INFO))

在异常情况下,我会收到这样的日志消息:

INFO:mymodule:Finished call to 'mymodule.MyClass.myfunction' after 0.001(s), this was the 1st time calling it.

除了已经记录的内容之外,我还想记录实际的异常(1 行格式,最好不是堆栈跟踪)。有毅力能做到吗?还是我只需要捕获异常、打印并重新引发?

标签: pythonpython-tenacity

解决方案


推荐阅读