0

添加retry_error_callback以下代码后。异常被吞没。如何重新引发异常?只需添加不起作用raisecb()

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

def cb(s):
    logging.error(f'Retrying get_file() failed. {s}')
    # raise  # not working

@retry(wait=wait_exponential(multiplier=1, min=2, max=60), 
       stop=stop_after_attempt(3),
       retry_error_callback=cb
       )
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()
4

0 回答 0