开发者

Python : Running a loop during a precise duration

开发者 https://www.devze.com 2023-02-02 02:57 出处:网络
I need to run a loop during a precise duration. For example, the code I\'m trying to make would look like开发者_开发百科 that :

I need to run a loop during a precise duration. For example, the code I'm trying to make would look like开发者_开发百科 that :

initialize and lauch timer

while timer<10000sec:
   do things

Do you know how to do this ?

Thank you :)


stop = time.time()+10000
while time.time() < stop:
  do things

This requires that each run through the loop is sufficiently short so that you read the current time often enough (for the preciseness that you want to achieve).

0

精彩评论

暂无评论...
验证码 换一张
取 消