I am new to python. I am trying to create a retry decorator that, when applied to a function, will keep retrying until some criteria is met (for simplicity, say retry 10 times).
def retry():
def wrapper(func):
for i in range(0,10):
try:
func()
break
except:
continue
return wrapper
Now that will retry on any exception. How can I change it such that it retries on specific exceptions. e.g, I want to use it like:
@retry(ValueError, AbcError)
def myfunc():
//do something
I want myfunc to be retried only of it throws ValueError or AbcError.
breaknow. Thanks!. Edit: I think it was wrong logic for retry. I just need theforloop I think