【问题标题】:Gevent pywsgi server used with gunicorn?Gevent pywsgi 服务器与 gunicorn 一起使用?
【发布时间】:2018-12-27 17:28:54
【问题描述】:

我有一个烧瓶应用程序设置来在我的代码中使用 gevent WSGIServer。我还在命令行上运行 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()

在命令行上我运行 gunicorn 之类的:

gunicorn -w 4 myapp:application

我的代码中是否需要 WSGIServer,或者只是在默认的烧瓶服务器上将其作为 application.run() 运行?

【问题讨论】:

    标签: flask gunicorn gevent


    【解决方案1】:

    根据Standalone WSGI Containers,gunicorn 和 gevent.pywsgi 都是 WSGI Containers,gunicorn 只对名为 application 的条目进行 reconize。
    所以if __name__ == '__main__':下面的代码不再有用了。
    如果你想使用 gevent,你可以这样做:

    gunicorn -k gevent -w 4 myapp:application
    

    【讨论】:

      猜你喜欢
      • 2017-10-14
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 2014-02-01
      • 2012-11-13
      • 1970-01-01
      相关资源
      最近更新 更多