Time as stopping condition of infinite loop

后端 未结 5 1832
我在风中等你
我在风中等你 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:32

    It stops every tenth minute: 1:10, 2:10, 3:10, etc. In order to do that, use something like:

    import time
    
    # in outer loop
    inner_loop_start = time.time()
    
    # in inner loop
        now = time.time()
        if now - inner_loop_start > 60*10:
            # done= True and all that jazz
    

提交回复
热议问题