我想在Python上每60秒执行一次函数
我怎样才能异步做到这一点?
import threading
import time
def f():
print("hello world")
threading.Timer(3, f).start()
if __name__ == '__main__':
f()
time.sleep(20)
使用此代码,函数f在20秒内每3秒执行一次。最后它给出了一个错误,我认为这是因为threading.timer没有被取消。
相似问题