This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tenacity import (retry | |
,stop_after_attempt | |
,wait_fixed | |
,retry_if_exception_type | |
,stop_after_delay) | |
import httpx | |
import asyncio | |
import socket | |
@retry(stop=(stop_after_delay(3) | stop_after_attempt(5)),wait=wait_fixed(2),retry=retry_if_exception_type(Exception)) | |
async def stop_after_7_attempts(): #stop_after_10s_or_5_retries | |
print("Stopping after 7 attempts") | |
resp=httpx.get("https://www.youtube.com/aasd") | |
if (resp.status_code == 404): raise Exception("404 Not working") | |
print(" trying ... " ) | |
asyncio.run(stop_after_7_attempts()) |