From 0af1adc5fe43005b5ee11c28276d938cce9b607d Mon Sep 17 00:00:00 2001 From: timotheyca Date: Sun, 28 Nov 2021 00:21:53 +0300 Subject: [PATCH] start_app + run_app --- v6d0auth/run-server.py | 6 ++---- v6d0auth/run_app.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 v6d0auth/run_app.py diff --git a/v6d0auth/run-server.py b/v6d0auth/run-server.py index f4580cc..4edabf2 100644 --- a/v6d0auth/run-server.py +++ b/v6d0auth/run-server.py @@ -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))) diff --git a/v6d0auth/run_app.py b/v6d0auth/run_app.py new file mode 100644 index 0000000..09265a8 --- /dev/null +++ b/v6d0auth/run_app.py @@ -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)