Run a python function every second

后端 未结 6 852
我寻月下人不归
我寻月下人不归 2020-12-16 08:08

What I want is to be able to run a function every second, irrelevant of how long the function takes (it should always be under a second). I\'ve considered a number of option

6条回答
  •  攒了一身酷
    2020-12-16 08:59

    Threading may be a good choice. The basic concept is as follows.

    import threading
    
    def looper():    
        # i as interval in seconds    
        threading.Timer(i, looper).start()    
        # put your action here
        foo()
    
    #to start 
    looper()
    

提交回复
热议问题