title: Efficiency of infinite loop to service GPIO
body: <p>I'm using Python on Raspbian (a type of linux) on the Raspberry Pi (an embedded processor board) to monitor GPIO inputs.</p>
  
  <p>See simplified version of my code below. I have an infinite loop in the python script waiting for something to happen on a GPIO i/p. Is this the correct way to do it? I.e. does this mean that the CPU is running at full whack just going round this loop, leaving no CPU cycles for other stuff? Especially as I need to be running other things in parallel (e.g. the browser).</p>
  
  <p>Also what happens if the CPU is busy doing something else and a GPIO i/p changes? Does the GPIO event get stored somewhere so it is eventually serviced, or does it just get lost?</p>
  
  <p>Is there a better way of doing this?</p>
  
  <p>(For your answers, please note that I'm new to linux, and v. new to python and real-time programming)</p>
  
  <pre><code>#!/usr/bin/python
  import RPi.GPIO as GPIO
  GPIO.setmode(GPIO.BOARD)
  GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  
  def ButtonHandler(channel):
      print "Button pressed " + str(channel)
      # do stuff here
  
  GPIO.add_event_detect(16, GPIO.FALLING, callback=ButtonHandler, bouncetime=200)
  
  while True:
      pass
  </code></pre>