10

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?

Alex Benz
  • 395
  • 4
  • 14
  • I am curious why I would want to use gunicorn at all with an async hyper fast web server. My experience is that gunicorn is not terribly efficient. And wouldn't multiple processes on the server machine cause a lot of context switching meaning that none of the process aiohttp event loops are as efficient as they might otherwise be? – Samantha Atkins Mar 29 '19 at 17:37

2 Answers2

8

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
1

The demo does not support gunicorn yet.

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

Thanks for report.

Andrew Svetlov
  • 16,730
  • 8
  • 66
  • 69