31 lines
399 B
Python
31 lines
399 B
Python
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)
|