【问题标题】:Python 3.6 web Sanic + uwsgiPython 3.6 网络 Sanic + uwsgi
【发布时间】:2018-03-14 05:48:07
【问题描述】:

我正在尝试让我的 sanic webapp 与 uwsgi 一起工作,这就是我所做的:

调用我的 uwsgi.ini 文件:

uwsgi uwsgi.ini

内容:

[uwsgi]
http = :8001
wsgi-file = wsgi.py
asyncio  = 10

wsgi.py:

from app import app as application

if __name__ == "__main__":
    application.run()

app.py:

import asyncio
import uvloop

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

from sanic import Sanic
from sanic.response import json

app = Sanic(__name__)

@app.route("/")
async def test(request):
    return json({"foo": "bar"})

当我请求时,我得到:

TypeError: __call__() takes 1 positional argument but 3 were given

我检查了 uwsgi 和 Sanic 文档,但可以找到任何提示...有人可以帮我解决这个问题吗?谢谢和问候!

【问题讨论】:

    标签: python asynchronous async-await uwsgi sanic


    【解决方案1】:

    据我所知,sanic 还不兼容 WSGI Make sanic WSGI compliant. #250

    您可以使用 gunicorn 运行它,例如:

    gunicorn myapp:app --bind 0.0.0.0:8080 --worker-class sanic.worker.GunicornWorker
    

    您还可以增加 sanic worker 数量以在多个 CPU 内核上运行:

    app.run(host='0.0.0.0', port=1337, workers=4)
    

    按照本指南:Deploying

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 2018-06-07
      • 2019-01-01
      • 2017-10-08
      相关资源
      最近更新 更多