title: Raspberry Pi Python loop stop to work
body: <p>i manipulate a sensor : HC SR04 to capture a distance.
  I'm a newbie in Python and RPI. My code work, I capture distance during a time but one moment the script stop... </p>
  
  <p>My code :</p>
  
  <pre><code>GPIO.setmode(GPIO.BCM)
  
  GPIO_TRIGGER = 23
  GPIO_ECHO = 24
  
  GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
  GPIO.setup(GPIO_ECHO, GPIO.IN)
  
  def main():
      global state
      print("ultrasonic")
      while True:
          print "1s second refresh.."
          time.sleep(1)
  
          i = 0
          datas = []
          average = 0
  
          while i&lt; 1:
              GPIO.output(GPIO_TRIGGER, False)
  
              time.sleep(C.time['count'])
              GPIO.output(GPIO_TRIGGER, True)
              time.sleep(0.00001)
              GPIO.output(GPIO_TRIGGER, False)
  
              while GPIO.input(GPIO_ECHO) == 0:
                  start = time.time()
  
              while GPIO.input(GPIO_ECHO) == 1:
                  stop = time.time()
  
              distance = (stop-start) * 17000
  
              print "Distance : %.1f" % distance
  
          average = F.getAverage(datas)
          print "Average: %.1f" % average
  
      GPIO.cleanup()
  </code></pre>
  
  <p>The code stop here</p>
  
  <pre><code>while GPIO.input(GPIO_ECHO) == 0:
                  start = time.time()
  </code></pre>
  
  <p><strong>THE SOLUTION : with a sample timeout :</strong></p>
  
  <pre><code>now = time()
  
  while GPIO.input(self.gpio_echo) == 0 and time()-now&lt;waitTime:
      pass
  </code></pre>