自己用装饰器写了一个,有什么需要改进的地方吗?
def retry(attempt):
def decorator(func):
def wrapper(*args, **kw):
att = 0
while att < attempt:
try:
return func(*args, **kw)
except Exception as e:
att += 1
return wrapper
return decorator
@rety(attempt=3)
def get_response(url):
import requests
r = requests.get('http://xxx')
return r.content