Alex Benz
Alex Benz

Reputation: 395

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?

Upvotes: 10

Views: 5128

Answers (2)

Grygorii Iermolenko
Grygorii Iermolenko

Reputation: 331

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

Upvotes: 8

Andrew Svetlov
Andrew Svetlov

Reputation: 17366

The demo does not support gunicorn yet.

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

Thanks for report.

Upvotes: 1

Related Questions