"""如何批量控制装饰器是否执行,只需要在原有的基础上添加外层函数。进行bool值控制即可"""
import time
Flag=False
def wrapper_out(Flag):
def wrapper(func):
def inner(*args,**kwargs):
if Flag:
start_time=time.time()
time.sleep(4)
ret=func(*args,**kwargs)
dur=time.time()-start_time
print('该函数执行时间:%s' %dur)
return ret
else:
ret = func(*args, **kwargs)
return ret
return inner
return wrapper
@wrapper_out(Flag)
def lin():
print("NIMO")
return "over"
link=lin()
print(link)