标签:射击 fun app imp ret local star return 实现
#装饰器实现简易限制函数调用频率,如10秒一次
import math
import time
def wrapper(func):
start_time =0
def inner(*args,**kwargs):
nonlocal start_time
t = time.time() - start_time
if t >= 10:
start_time =time.time()
ret = func(*args, **kwargs)
return ret
else:
print(f"技能还在冷却当中,倒计时{math.ceil(10-t)}秒")
return inner
@wrapper
def foo():
print("开始瞄准,射击")
while True:
foo()
time.sleep(1)
标签:射击 fun app imp ret local star return 实现
原文地址:https://www.cnblogs.com/niucunguo/p/12038465.html