title: Python Alarm Clock
body: <p>I've made this little alarm clock with a little help from my brother. I tried it last night, with out the <code>nonBlockingRawInput</code> and that worked fine, but with the <code>nonBlockingRawInput</code> it didn't work. Today I've tried it but neither of them work! I will post the code with the <code>nonBlockingRawInput</code> and the "non" file. If you want the code without <code>nonBlockingRawInput</code>, just ask.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>alarm rpi.py</strong>:</p>
  
  <pre><code>import time
  import os
  from non import nonBlockingRawInput
  
  name = input("Enter your name.")
  
  print("Hello, " + name)
  
  alarm_HH = input("Enter the hour you want to wake up at")
  alarm_MM = input("Enter the minute you want to wake up at")
  
  print("You want to wake up at " + alarm_HH + ":" + alarm_MM)
  
  while True:
      now = time.localtime()
      if now.tm_hour == int(alarm_HH) and now.tm_min == int(alarm_MM):
          print("ALARM NOW!")
          os.popen("open mpg321 /home/pi/voltage.mp3")
          break
  
      else:
          print("no alarm")
      timeout = 60 - now.tm_sec
      if nonBlockingRawInput('', timeout) == 'stop':
          break
  </code></pre>
  
  <p><strong>non.py</strong>:</p>
  
  <pre><code>import signal
  
  class AlarmException(Exception):
      pass
  
  def alarmHandler(signum, frame):
      raise AlarmException
  
  def nonBlockingRawInput(prompt='', timeout=20):
      signal.signal(signal.SIGALRM, alarmHandler)
      signal.alarm(timeout)
      try:
          text = input(prompt)
          signal.alarm(0)
          return text
      except AlarmException:
          pass
      signal.signal(signal.SIGALRM, signal.SIG_IGN)
      return ''
  </code></pre>