Time as stopping condition of infinite loop

后端 未结 5 1925
我在风中等你
我在风中等你 2021-01-29 02:11
# run infinitly
while(True):

  done = False;

  while(not done):
    #Do Stuff
    #Main Program

    #stopping condition of inner while loop
    if datetime.datetime.n         


        
5条回答
  •  甜味超标
    2021-01-29 02:43

    There are various ways to do it, but keeping close to your original design, I'd code the inner loop as:

    while(not done):
        if datetime.datetime.now().minute % 10 == 0:
            done = True
        else:
            time.sleep(60-datetime.datetime.now().second)
    

    (I'm assuming what you were trying to do with that second if was sleep until the next minute when you weren't ready to exit the loop.)

提交回复
热议问题