Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Created December 19, 2023 10:23
Show Gist options
  • Save j-thepac/b99b3e31b7e0b3304c6c403fa202ee5f to your computer and use it in GitHub Desktop.
Save j-thepac/b99b3e31b7e0b3304c6c403fa202ee5f to your computer and use it in GitHub Desktop.
Tenacity with Asyncio
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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment