Run a python function every second

后端 未结 6 853
我寻月下人不归
我寻月下人不归 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:47

    I would like to recommend the following code. You can replace the True with any condition if you want.

    while True:
    time.sleep(1) #sleep for 1 second
    func()    #function you want to trigger
    

    Tell me if it works.

提交回复
热议问题