title: How can I make pybluez return a list of discovered devices every X seconds and then repeat?
body: <p>I've been trying to figure out how I can use <a href="http://code.google.com/p/pybluez/" rel="nofollow noreferrer">pybluez</a> to monitor nearby devices...</p>
  
  <p>I want to be able to run my program and have it search for devices every 20 seconds. The problem is, how do I get pybluez to place nicely? :/</p>
  
  <p>Using their example code <a href="http://code.google.com/p/pybluez/source/browse/trunk/examples/simple/inquiry.py" rel="nofollow noreferrer">http://code.google.com/p/pybluez/source/browse/trunk/examples/simple/inquiry.py</a>, it's easy enough to get it to discover devices. You run that code and it'll spit out MAC address and, if you choose, the device names.</p>
  
  <p>How can I put this in a loop? I've been playing around with the following code but it's failing >.&lt;</p>
  
  <pre><code>import bluetooth
  
  def search():
     while True:
        devices = bluetooth.discover_devices(lookup_names = True)
  
        yield devices
  
  for addr, name in search():
     print "{0} - {1}".format(addr, name)
  </code></pre>