thestraf/onceasecond.py

31 lines
399 B
Python
Raw Permalink Normal View History

2021-10-02 18:51:26 +02:00
import time
def onceasecond(func):
#global lastt
lastt=0
def fun(*args,**kwargs):
#global lastt
t=time.time()
if t-fun.lastt>1:
fun.lastt=t
func(*args,**kwargs)
fun.lastt=lastt
return fun
if __name__=="__main__":
@onceasecond
def printi(i):
print(i)
i=0
while True:
i+=1
printi(i)