time - Python loop to run for certain amount of seconds -
time - Python loop to run for certain amount of seconds -
i have while loop, , want maintain running through 15 minutes. currently:
while true: #blah blah blah (this runs through, , restarts. need go on doing except after 15 minutes exits loop)
thanks!
try this:
import time t_end = time.time() + 60 * 15 while time.time() < t_end: # whatever this run 15 min x 60 s = 900 seconds.
function time.time returns current time in seconds since 1st jan 1970. value in floating point, can utilize sub-second precision. in origin value t_end calculated "now" + 15 minutes. loop run until current time exceeds preset ending time.
python time timer while-loop
Comments
Post a Comment