ai项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
881 B

from functools import wraps
import time
def retry(name='name', for_work=1, time_sleep=2):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
a = 0
while True:
try:
res = func(*args, **kwargs)
if res:
return res
else:
print(name, ':异常结果重新处理')
time.sleep(time_sleep)
except Exception as e:
print(f'[{name}]:{e}')
time.sleep(time_sleep)
a += 1
if for_work == 0:
continue
if a >= for_work:
break
print(f'[{name}]:多次请求失败')
return False
return wrapper
return decorator