Elektito
Elektito

Reputation: 4155

Running aiohttp application as a coroutine

I have an asyncio app and I want to add a simple REST API to it using aiohttp. As far as I can see, I can either create an aiohttp app and run it with aiohttp.web.run_app on another thread, or I'd have to forget about the app and use the lower level aiohttp.web.Server API. Is there a way I can use aiohttp.web.Application and then run the web application as a coroutine instead of using run_app?

Upvotes: 5

Views: 1206

Answers (1)

Andrew Svetlov
Andrew Svetlov

Reputation: 17356

Just open sourced code for aiohttp.web:run_app (https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web.py#L413-L467) and see how it's implemented.

You could do the same but don't call blocking loop.run_forever().

Upvotes: 6

Related Questions