使用gunicorn运行aiohttp服务器

Ale*_*enz 6 python python-3.x gunicorn aiohttp

我正在尝试使用Gunicorn运行基于aiohttp的服务器.

这是命令:

gunicorn aiohttpdemo_polls:app --bind 127.0.0.1:8080
Run Code Online (Sandbox Code Playgroud)

它返回:

Failed to find application: 'aiohttpdemo_polls' 
Run Code Online (Sandbox Code Playgroud)

但是当我使用python -m运行它时,如下所示:

python -m aiohttpdemo_polls
Run Code Online (Sandbox Code Playgroud)

它工作正常.代码可以在这里找到,这是aiohttp repo中的一个演示应用程序.也尝试过如下:

gunicorn aiohttpdemo_polls.main:app --bind 127.0.0.1:8080
Run Code Online (Sandbox Code Playgroud)

但它也没有运行服务器.它回来了

Failed to find application: 'aiohttpdemo_polls.main'
Run Code Online (Sandbox Code Playgroud)

知道在哪里进一步寻找解决问题的方法吗?

Gry*_*nko 8

aiohttp 3.1 支持协程作为应用工厂,例如:

async def my_web_app():
    app = web.Application()
    app.router.add_get('/', index)
    return app
Run Code Online (Sandbox Code Playgroud)

aiohttpdemo_polls 的当前实现使用这种方法。它可以开始

gunicorn aiohttpdemo_polls.main:init_app --bind localhost:8080 --worker-class aiohttp.GunicornWebWorker
Run Code Online (Sandbox Code Playgroud)


And*_*lov 1

该演示尚不支持gunicorn。

我提出了一个问题:https ://github.com/aio-libs/aiohttp-demos/issues/10

感谢您的报告。