编码
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()
输出
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
....
如何记录它正在重试?如
Error. Retrying 1...
...
Error. Retrying 2...
...