title: Responding to concurrent requests with Flask and eventlet
body: <p>I try to set up a minimal Flask application that uses <a href="http://eventlet.net/" rel="noreferrer">eventlet</a> to respond to concurrent requests instantly instead of blocking and responding to one request after the other (as the standard Flask debugging webserver does).</p>
  
  <p>Prerequisites:</p>
  
  <pre><code>pip install Flask
  pip install eventlet
  </code></pre>
  
  <p>From my understanding by what I found so far on the internet, it should work like this:</p>
  
  <pre><code># activate eventlet
  import eventlet
  eventlet.monkey_patch()
  
  from flask import Flask
  
  import datetime
  from time import sleep
  
  # create a new Flask application
  app = Flask(__name__)
  
  # a short running task that returns immediately
  @app.route('/shortTask')
  def short_running_task():
    start = datetime.datetime.now()
    return 'Started at {0}, returned at {1}'.format(start, datetime.datetime.now())
  
  # a long running tasks that returns after 30s
  @app.route('/longTask')
  def long_running_task():
    start = datetime.datetime.now()
    sleep(30)
    return 'Started at {0}, returned at {1}'.format(start, datetime.datetime.now())
  
  # run the webserver
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p>When running this file, then opening <code>http://localhost:5000/longTask</code> in a webbrowser tab and while it is still processing opening another tab with <code>http://localhost:5000/shortTask</code>, I would expect the second tab to return immediately while the first tab is still loading. However, similar to when running this on the standard Werkzeug server, the second tab only returns just after the first one is finished after 30s.</p>
  
  <p>What is wrong here?
  By the way, would this be what is commonly referred to as a "production ready webserver" for Flask, given that there are only few concurrent users to be expected (5 at most)?</p>
  
  <p>By the way, when I use <a href="http://flask-socketio.readthedocs.org/en/latest/" rel="noreferrer">the Flask-socketio library</a> to run the webserver which, according to the documentation, automatically chooses eventlet if it is installed, then it works as expected.</p>
  
  <p>Complete example with Flask-socketio:</p>
  
  <pre><code># activate eventlet
  import eventlet
  eventlet.monkey_patch()
  
  from flask import Flask
  from flask_socketio import SocketIO
  
  import datetime
  from time import sleep
  
  # create a new Flask application
  app = Flask(__name__)
  
  # activate Flask-socketio
  socketio = SocketIO(app)
  
  # a short running task that returns immediately
  @app.route('/shortTask')
  def short_running_task():
    start = datetime.datetime.now()
    return 'Started at {0}, returned at {1}'.format(start, datetime.datetime.now())
  
  # a long running tasks that returns after 30s
  @app.route('/longTask')
  def long_running_task():
    start = datetime.datetime.now()
    sleep(30)
    return 'Started at {0}, returned at {1}'.format(start, datetime.datetime.now())
  
  # run the webserver with socketio
  if __name__ == '__main__':
      socketio.run(app, debug=True)
  </code></pre>