-
Notifications
You must be signed in to change notification settings - Fork 113
Open
Description
When i use retry decorator with async def, it not working, this is my test code:
@retry(tries=3)
async def test():
print('test')
raise Exception('test')
if __name__ == "__main__":
asyncio.run(test())test
Traceback (most recent call last):
File "/home/ayclqt/Dev/stream-api/test.py", line 23, in <module>
asyncio.run(test())
~~~~~~~~~~~^^^^^^^^
File "/home/ayclqt/.local/share/uv/python/cpython-3.13.1-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 194, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "/home/ayclqt/.local/share/uv/python/cpython-3.13.1-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/home/ayclqt/.local/share/uv/python/cpython-3.13.1-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 720, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "/home/ayclqt/Dev/stream-api/test.py", line 19, in test
raise Exception('test')
Exception: test
It just print "test" 1 time, but if I change it to sync, it works normally:
@retry(tries=3)
def test():
print('test')
raise Exception('test')
if __name__ == "__main__":
test()test
test
test
Traceback (most recent call last):
File "/home/ayclqt/Dev/stream-api/test.py", line 23, in <module>
test()
~~~~^^
File "/home/ayclqt/Dev/stream-api/.venv/lib/python3.13/site-packages/decorator.py", line 235, in fun
return caller(func, *(extras + args), **kw)
File "/home/ayclqt/Dev/stream-api/.venv/lib/python3.13/site-packages/retry/api.py", line 73, in retry_decorator
return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
logger)
File "/home/ayclqt/Dev/stream-api/.venv/lib/python3.13/site-packages/retry/api.py", line 33, in __retry_internal
return f()
File "/home/ayclqt/Dev/stream-api/test.py", line 19, in test
raise Exception('test')
Exception: test
Metadata
Metadata
Assignees
Labels
No labels