title: Change a variable every n seconds
body: <p>I am writing a script that needs to clear a variable every 5 seconds while the main program is running.</p>
  
  <p>The following is my function</p>
  
  <pre><code>def clearBeepCounter():
  while (checkforlowbatt == 1):
      sleep(lowbattdelay)
      beepscounted = 0
  </code></pre>
  
  <p>But using sleep halts the entire script. Can I keep resetting this variable as my main loop runs? </p>
  
  <pre><code>while (monitoringenabled == 1 &amp; alert == 0):
  sounddetected = wiringpi.digitalRead(19)
  if (sounddetected == 1):
      beepscounted = beepscounted + 1
      lowbattbeepscounted = lowbattbeepscounted + 1 
  
  if (beepscounted &gt; 4):
      alert = 1
      q.put(2)
  
  if (lowbattbeepscounted &gt; 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 &amp; alert== 0): print("0")
  </code></pre>
  
  <p>Is os.fork the way to go here?</p>