Time as stopping condition of infinite loop

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

    Expanding from my comment above:

    tic = datetime.datetime.now()
    
    while True:
    
        # do stuff
    
        toc = datetime.datetime.now() - tic
        if toc.minute > 10:
            tic = datetime.datetime.now();
            time.sleep(60-datetime.datetime.now().second)
    

    I have removed the "done" variable, since it conveys a meaning of finished. By reading your code, though, it seems you are actually pausing an ever ongoing process, actually.

    Hope this helps!

提交回复
热议问题