与 gunicorn 一起使用的 Gevent pywsgi 服务器?
Gevent pywsgi server used with gunicorn?
我有一个 flask 应用程序设置,可以在我的代码中使用 gevent WSGIServer。我也在命令行运行ning gunicorn 启动服务器。
当 运行 gunicorn 时,我是否应该在代码中使用 WSGI 服务器?目前看起来像这样:
from flask import Flask
from gevent.pywsgi import WSGIServer
application = Flask(__name__)
@application.route("/")
def hello():
return "hello"
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
WSGIServer(('', port), application).serve_forever()
在命令行上我是 运行ning gunicorn 喜欢:
gunicorn -w 4 myapp:application
我的代码中是否需要 WSGIServer,或者只是 运行 默认 Flask 服务器上的 application.run()?
根据Standalone WSGI Containers,gunicorn和gevent.pywsgi都是WSGI容器,gunicorn只重新定义名为application.[=16=的条目]
所以下面的代码 if __name__ == '__main__':
没有用了。
如果你想使用gevent,你可以这样做:
gunicorn -k gevent -w 4 myapp:application
我有一个 flask 应用程序设置,可以在我的代码中使用 gevent WSGIServer。我也在命令行运行ning gunicorn 启动服务器。
当 运行 gunicorn 时,我是否应该在代码中使用 WSGI 服务器?目前看起来像这样:
from flask import Flask
from gevent.pywsgi import WSGIServer
application = Flask(__name__)
@application.route("/")
def hello():
return "hello"
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
WSGIServer(('', port), application).serve_forever()
在命令行上我是 运行ning gunicorn 喜欢:
gunicorn -w 4 myapp:application
我的代码中是否需要 WSGIServer,或者只是 运行 默认 Flask 服务器上的 application.run()?
根据Standalone WSGI Containers,gunicorn和gevent.pywsgi都是WSGI容器,gunicorn只重新定义名为application.[=16=的条目]
所以下面的代码 if __name__ == '__main__':
没有用了。
如果你想使用gevent,你可以这样做:
gunicorn -k gevent -w 4 myapp:application