我想让我的功能运行一段特定的时间,例如5秒钟;我该怎么做?
喜欢,
def my_function():
while(time == 10 seconds):
......... #run this for 10 seconds
def my_next_function():
while(time == 5 seconds):
......... #run this for 5 seconds
这一定会对您有帮助。
import time
def myfunc():
now=time.time()
timer = 0
while timer != 10:
end = time.time()
timer = round(end-now)
def mynextfunc():
now=time.time()
timer = 0
while timer != 5:
end = time.time()
timer = round(end-now)
myfunc()
print "myfunc() exited after 10 seconds"
mynextfunc()
print "mynextfunc() exited after 5 seconds"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句