我正在编写一个脚本,该脚本需要在主程序运行时每5秒清除一次变量。
以下是我的功能
def clearBeepCounter():
while (checkforlowbatt == 1):
sleep(lowbattdelay)
beepscounted = 0
但是使用睡眠会暂停整个脚本。我可以在主循环运行时继续重置此变量吗?
while (monitoringenabled == 1 & alert == 0):
sounddetected = wiringpi.digitalRead(19)
if (sounddetected == 1):
beepscounted = beepscounted + 1
lowbattbeepscounted = lowbattbeepscounted + 1
if (beepscounted > 4):
alert = 1
q.put(2)
if (lowbattbeepscounted > 3):
lowbatt = 1
lowbattbeepscounted = 3 # dont want this to take up more memory if it isnt changed all day.
q.put(1)
sleep(refreshrate)
if (lowbatt == 1): print ("1")
elif (alert == 1): print ("2")
elif (lowbatt == 0 & alert== 0): print("0")
os.fork是去这里的路吗?