@retry(retry=retry_if_exception_type(requests.RequestException)) def fetch_data(): ... Retry based on return value or exception message.
retryer = Retrying(stop=stop_after_attempt(3)) with retryer: unreliable_operation() Built-in logging of retry events (supports custom logger). 11. Integration with asyncio , Tornado , gevent Event-loop aware waiting. Example: Resilient HTTP Client from tenacity import ( retry, stop_after_attempt, wait_exponential, retry_if_exception_type, before_sleep_log ) import requests import logging logging.basicConfig(level=logging.INFO) tenacity client
@retry(...) def op(): ... op.retry.statistics # e.g., 'attempt_number': 3, 'delay': 2.1 Native support for async def functions. 9. Retrying Arbitrary Blocks (not just functions) Use Retrying context manager: @retry(retry=retry_if_exception_type(requests