Skip to content

Conversation

@asaf-kali
Copy link

@asaf-kali asaf-kali commented Apr 18, 2024

POC for this issue.
Usage:

@retry()
async def make_trouble():
    # Some flaky code
    pass

async def some_function():
    await make_trouble()

while _tries:
try:
return f()
return await f()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to conditionally await by calling inspect.isawaitable. Not sure if you can keep the signature without the await, or do an equivalent of an await call using some library function:

  is_async = False
  value = f()
  if inspect.isawaitable(value):
     is_async = True
     value = await value
  return value

is_async could potentially be used in the except block to determine which sleep method to use

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to keep the signature intact. And also went with inspect module to find out whether it's dealing with an async function: my implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants