lxl0928 / retrying-async Goto Github PK
View Code? Open in Web Editor NEWPython @retry Async
License: MIT License
Python @retry Async
License: MIT License
`import asyncio
from retrying_async import retry
counter = 0
@Retry(attempts=3, delay=3)
async def fn():
global counter
counter += 1
if counter == 1:
raise RuntimeError
async def main():
await fn()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
assert counter == 2
loop.close()
`
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/WorkSpace/bili_huahuo_spider/tests/test_retry.py", line 28, in
loop.run_until_complete(main())
File "/usr/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete
return future.result()
File "/home/WorkSpace/bili_huahuo_spider/tests/test_retry.py", line 23, in main
await fn()
File "/home/.virtualenvs/bili_huahuo_spider/lib/python3.7/site-packages/retrying_async.py", line 169, in wrapped
raise fallback from exc
retrying_async.RetryError
sys:1: RuntimeWarning: coroutine 'fn' was never awaited
I am using the retry
decorator with an async method:
import asyncio
from retrying_async import retry
@retry(attempts='infinite', delay=3)
async def a():
await b()
while True:
try:
print("Hi")
await asyncio.sleep(1)
except Exception as exception:
print(type(exception))
print("Exception encountered")
raise exception
async def b():
print("hi")
if __name__ == "__main__":
asyncio.run(a())
Getting this exception here:
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
<class 'concurrent.futures._base.CancelledError'>
Exception encountered
Any suggestions here ? This does not happen if I remove the retry
decorator.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.