Earlier I was using Waitress. Now I\'m using Gevent to run my Flask app that has only one API
from flask import Flask, request, jsonify
import documentUtil
fr
Not sure, however I think adding thread param in server object can solve the problem.
http_server = WSGIServer(('127.0.0.1', 8000), app, numthreads=50)
source: https://f.gallai.re/wsgiserver
"""index.py"""
from flask import Flask
from flask import jsonify
app = Flask(__name__)
@app.route('/')
def index():
"""Main page"""
doc = {
'site': 'stackoverflow',
'page_id': 6347182,
'title': 'Using Gevent in flask'
}
return jsonify(doc)
# To start application
gunicorn -k gevent --bind 0.0.0.0 index:app
k : worker_class
--bind : bind address
# See https://docs.gunicorn.org/en/latest/settings.html
We use Gunicorn to run Flask in multiple processes. You get more juice out of python that way + auto restarts and stuff. Sample config file:
import multiprocessing
bind = "0.0.0.0:80"
workers = (multiprocessing.cpu_count() * 2) + 1
# ... additional config
Then run with something like
gunicorn --config /path/to/file application.app