我想在Python上每60秒执行一次函数,但我不希望同时被阻塞.
我该如何异步进行?
import threading
import time
def f():
print("hello world")
threading.Timer(3, f).start()
if __name__ == '__main__':
f()
time.sleep(20)
Run Code Online (Sandbox Code Playgroud)
使用此代码,函数f在20秒time.time内每3秒执行一次.最后它给出了一个错误,我认为这是因为threading.timer还没有被取消.
我该如何取消?
提前致谢!