def func(repeat=True):
time.sleep(20) #simulating the body of func
if repeat:
time.sleep(10)
func()
check = theading.Thread(targe=func)
func()
基本上,“ func”每10秒运行一次,但是我希望能够随时使用func(repeat = False)调用“ func”。我从不希望运行两个'func'实例。因此,如果我调用func(repeat = False),我希望它等待'func'到达'time.sleep(10)',然后调用自身。完成后,我希望原始功能可以继续运行。
我知道这与异步和等待有关,但是我对它们还不够熟悉。