Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running aiohttp server using gunicorn

I am trying to run a aiohttp based server using Gunicorn.

Here is the command:

gunicorn aiohttpdemo_polls:app --bind 127.0.0.1:8080

It returns:

Failed to find application: 'aiohttpdemo_polls' 

But when I am running it using python -m like below:

python -m aiohttpdemo_polls

It works fine. The code can be found from here which is a demo app in the aiohttp repo. Also tried it like below:

gunicorn aiohttpdemo_polls.main:app --bind 127.0.0.1:8080

But its also not running the server. It returns

Failed to find application: 'aiohttpdemo_polls.main'

Any idea where to look further for fixing the issue?

like image 821
Alex Benz Avatar asked Nov 13 '17 14:11

Alex Benz


2 Answers

aiohttp 3.1 supports coroutine as application factory, such as:

async def my_web_app():
    app = web.Application()
    app.router.add_get('/', index)
    return app

Current implementation of aiohttpdemo_polls uses this approach. It can be started with

gunicorn aiohttpdemo_polls.main:init_app --bind localhost:8080 --worker-class aiohttp.GunicornWebWorker
like image 92
Grygorii Iermolenko Avatar answered Nov 02 '22 07:11

Grygorii Iermolenko


The demo does not support gunicorn yet.

I filed an issue: https://github.com/aio-libs/aiohttp-demos/issues/10

Thanks for report.

like image 1
Andrew Svetlov Avatar answered Nov 02 '22 09:11

Andrew Svetlov