start_app + run_app

This commit is contained in:
AF 2021-11-28 00:21:53 +03:00
parent 0351d26064
commit 0af1adc5fe
2 changed files with 27 additions and 4 deletions

View File

@ -1,10 +1,8 @@
import asyncio
from aiohttp import web
from v6d0auth.app import get_app
from v6d0auth.config import port, host
from v6d0auth.run_app import run_app
if __name__ == '__main__':
loop = asyncio.get_event_loop()
web.run_app(get_app(loop), host=host, port=port, loop=loop)
loop.run_until_complete(run_app(get_app(loop)))

25
v6d0auth/run_app.py Normal file
View File

@ -0,0 +1,25 @@
import asyncio
from aiohttp import web
from v6d0auth.config import port, host
__all__ = ('start_app', 'run_app',)
async def start_app(app: web.Application):
runner = web.AppRunner(app)
await runner.setup()
site = web.TCPSite(runner, host=host, port=port)
await site.start()
names = sorted(str(s.name) for s in runner.sites)
print(
"======== Running on {} ========\n"
"(Press CTRL+C to quit)".format(", ".join(names))
)
async def run_app(app: web.Application):
await start_app(app)
while True:
await asyncio.sleep(3600)