Sunday, 15 February 2015

python - How to make a function run for a particular time period? -



python - How to make a function run for a particular time period? -

i want create function run particular period 5 seconds; how can ?

like,

def my_function(): while(time == 10 seconds): ......... #run 10 seconds def my_next_function(): while(time == 5 seconds): ......... #run 5 seconds

this help you.

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"

python function python-2.7 python-3.x time

No comments:

Post a Comment