title: How to perform periodic task with Flask in Python
body: <p>I've been using <a href="http://flask.pocoo.org/">Flask</a> to provide a simple web API for my <a href="http://www.velleman.eu/products/view/?country=be&amp;lang=en&amp;id=351346">k8055</a> USB interface board; fairly standard getters and putters, and Flask really made my life a lot easier. </p>
  
  <p>But I want to be able to register changes of state as / near when whey happen.</p>
  
  <p>For instance, if I have a button connected to the board, I can poll the api for that particular port. But if I wanted to have the outputs directly reflect the outputs, whether or not someone was talking to the api, I would have something like this.</p>
  
  <pre><code>while True:
      board.read()
      board.digital_outputs = board.digital_inputs
      board.read()
      time.sleep(1)
  </code></pre>
  
  <p>And every second, the outputs would be updated to match the inputs. </p>
  
  <p>Is there any way to do this kind of thing under Flask? I've done similar things in Twisted before but Flask is too handy for this particular application to give up on it just yet...</p>
  
  <p>Thanks.</p>