title: How do i make a infinite loop with def function?
body: <p>I wrote a program that checks a log file every 5 seconds for a specifig word.
  When it finds that word it will make some noise and overwrite the Log file.
  The Problem is after some point I get:</p>
  
  <blockquote>
    <p>RuntimeError: maximum recursion depth exceeded while calling a Python object.  </p>
  </blockquote>
  
  <p>Is there a better way to make that loop? </p>
  
  <pre><code>import time
  import subprocess
  global playalarm
  
  def alarm():
      if "No answer" in open("/var/log/hostmonitor.log").read():
          print "Alarm!"
          playalarm=subprocess.Popen(['omxplayer','/root/Alarm/alarm.mp3'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,close_fds=True)
          log = open("/var/log/hostmonitor.log","w")
          log.write("Checked")
          log.close()
          time.sleep(5)
          playalarm.stdin.write('q')
          alarm()
      else:
          print"Checked"
          time.sleep(5)
          alarm()
  
  alarm()
  </code></pre>