Python loop to run for certain amount of seconds

后端 未结 6 1399
萌比男神i
萌比男神i 2020-12-02 22:08

I have a while loop, and I want it to keep running through for 15 minutes. it is currently:

while True:
    #blah blah blah

(this runs thro

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 22:44

    Simply You can do it

    import time
    delay=60*15    ###for 15 minutes delay 
    close_time=time.time()+delay
    while True:
          ##bla bla
          ###bla bla
         if time.time()>close_time
             break
    

提交回复
热议问题