标签: tenacity

Tenacity输出重试消息?

代码

import logging
from tenacity import retry, wait_incrementing, stop_after_attempt
import tenacity


@retry(wait=wait_incrementing(start=10, increment=10, max=100), stop=stop_after_attempt(3))
def print_msg():
    logging.info('Hello')
    logging.info("World")
    raise Exception('Test error')

if __name__ == '__main__':
    logging.basicConfig(
        format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
        datefmt='%d-%m-%Y:%H:%M:%S',
        level=logging.INFO)
    logging.info('Starting')
    print_msg()
Run Code Online (Sandbox Code Playgroud)

输出

21-11-2018:12:40:48,586 INFO     [retrier.py:18] Starting
21-11-2018:12:40:48,586 INFO     [retrier.py:8] Hello
21-11-2018:12:40:48,586 INFO     [retrier.py:9] World
21-11-2018:12:40:58,592 INFO     [retrier.py:8] Hello
21-11-2018:12:40:58,592 INFO     [retrier.py:9] World
21-11-2018:12:41:18,596 INFO     [retrier.py:8] Hello
21-11-2018:12:41:18,596 INFO     [retrier.py:9] World
21-11-2018:12:41:18,596 ERROR    [retrier.py:22] Received Exception
....
Run Code Online (Sandbox Code Playgroud)

如何记录重试?例如

Error. Retrying 1...
...
Error. Retrying 2...
...
Run Code Online (Sandbox Code Playgroud)

python python-tenacity tenacity

3
推荐指数
1
解决办法
3457
查看次数

标签 统计

python ×1

python-tenacity ×1

tenacity ×1