0

how to performed repeated task for a definite time like for 2 hours. Means loop terminate 2 hour from start time. I have research and got start time and end time but failed to make it as iteration condition. could you please help? Or some other best way mechanism to do this?

Thanks in advance. -MKS

1
  • And the task is supposed to run as fast as it can or just every K seconds? Commented Mar 25, 2012 at 14:20

1 Answer 1

4
from time import time, sleep
end_time = time() + x_hours * 3600 # time() is calculated in seconds

while time() < end_time:
    do_your_work()
    sleep(y_seconds)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.