title: Run while loop concurrently with Flask server
body: <p>I'm updating some LEDs using python. I've been doing this like so:</p>
  
  <pre><code>from LEDs import *
  myLEDs = LEDs()
  done = False
  while not done:
    myLEDs.iterate()
  </code></pre>
  
  <p>I wanted to use Flask to act as a bridge between some nice-looking ReactJS front-end I can run in my browser (to change the current pattern, etc) and the LED-controlling code in Python. </p>
  
  <p>I have Flask working fine, can handle HTTP requests, etc. I'm wondering how I can set <code>myLEDs.iterate()</code> to continuously run (or run on a rapid schedule) concurrently with my flask app, while still being able to communicate with one another, like so:</p>
  
  <pre><code>myLEDs = LEDs()
  
  @app.route('/changePattern',methods=['POST'])
  def changePattern():
    n = request.json['num']
    myLEDs.setPattern(n)
    return jsonify(**locals())
  
  if __name__ == '__main__':
    app.debug = True
    myLEDs.setToFrequentlyIterateAndStillTalkToFlask()
    app.run()
  </code></pre>
  
  <p>I came across <code>celery</code>, which seems like it would do the trick, but also seems like overkill for how simple my problem is. </p>
  
  <p>Is using Flask overkill for simply wanting a UI to manage my python back-end code? Is there a simpler library than Celery to use for running something in the background? </p>
  
  <p><strong>Edit</strong></p>
  
  <p>This is part of a larger project to develop an app with a Node-Webkit front-end attached to a Python backend. I'm open to changing my approach to this app if it doesn't seem feasible. </p>