是否可以使用aiohttp来运行多个gunicorn工人?

时间:2019-02-22 21:30:10

标签: python gunicorn python-asyncio aiohttp

我正在尝试使用aiohttp进行异步处理,以便由多个工作人员运行gunicorn服务器。

使用一个工作进程运行服务时,一切正常,但是使用多个进程运行时,服务失败

这似乎是由于以下错误引起的:https://bugs.python.org/issue22087 有没有解决该错误的方法?

最小代码:

Int

命令:from aiohttp import web async def handle(request): return web.Response(text='') app = web.Application() app.add_routes([web.get('/', handle)]) web.run_app(app)

错误:

gunicorn aio.simple_server:app  --worker-class aiohttp.GunicornWebWorker --workers 2

1 个答案:

答案 0 :(得分:4)

删除此:

web.run_app(app)

那是为了运行独立的aiohttp。假设您的代码另存为my_app.py,则可以使用以下命令运行一个进程:

python my_app.py

评论run_app,可以使用gunicorn来运行:

gunicorn my_app:app  --worker-class aiohttp.GunicornWebWorker --workers 2
相关问题