我想根据事件重复一个线程。 这是一组简化的代码:-
from threading import Thread
import time
def monitor() :
print("Monitor")
for i in range (1 ,3) :
print ("before call")
setalert.start()
print ("after call \n")
time.sleep(2)
return()
def setalert(threadname) :
print("Setalert \n")
return()
setalert = Thread( target=setalert, args=("setalert", ) )
c = monitor()
print ("done")
监视器中的时间功能正好可以让Setalert在重复之前有时间运行。 我看过的所有示例都显示了重复的Timer事件。那不是我想要的。 Setalert线程将由Raspberry Pi上的gpio活动触发,并且显然会做得比简单地打印“ Setalert”更多。