1. 代码 # 手写一个装饰器 def retry ( func ): def wrager ( * args , * * kwargs ): ret = func ( * args , * * kwargs ) max_retry = 3 number = 0 if not ret : while number max_retry : number = number + 1 print ( number ) ret = func ( *
1. 代码
# 手写一个装饰器def retry(func):
def wrager(*args, **kwargs):
ret = func(*args, **kwargs)
max_retry = 3
number = 0
if not ret:
while number < max_retry:
number = number + 1
print(number)
ret = func(*args, **kwargs)
if ret:
break
return wrager
@retry
def get_response():
return False
get_response()