我想编写一个控制程序调用频率的装饰器
def timer(step,duration):
def wrapper(func):
last_time = time.time()
def inner(*args, **kwargs):
global last_time
global duration
while duration >= 0:
current_time = time.time()
if current_time - last_time > step:
func(*args, **kwargs)
last_time = current_time
duration -= 1
else:
pass
return inner
return wrapper
@timer(100, 10)
def func(x):
x -= 1
print(x)
return x
func(100)