What is the best way to repeatedly execute a function every x seconds?

后端 未结 18 3090
不知归路
不知归路 2020-11-21 06:04

I want to repeatedly execute a function in Python every 60 seconds forever (just like an NSTimer in Objective C). This code will run as a daemon and is effectively like call

18条回答
  •  梦如初夏
    2020-11-21 06:34

        ''' tracking number of times it prints'''
    import threading
    
    global timeInterval
    count=0
    def printit():
      threading.Timer(timeInterval, printit).start()
      print( "Hello, World!")
      global count
      count=count+1
      print(count)
    printit
    
    if __name__ == "__main__":
        timeInterval= int(input('Enter Time in Seconds:'))
        printit()
    

提交回复
热议问题