v6d0auth/v6d0auth/run_app.py
2023-10-02 17:00:56 +00:00

40 lines
910 B
Python

import asyncio
import signal
from aiohttp import web
from v6d0auth.config import host, port
__all__ = (
"start_app",
"run_app",
)
async def start_app(app: web.Application, keepalive_timeout=75.0):
runner = web.AppRunner(
app,
keepalive_timeout=keepalive_timeout,
)
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)))
loop = asyncio.get_running_loop()
def sigtermed(*_args):
loop.create_task(app.shutdown())
signal.signal(signal.SIGTERM, sigtermed)
async def run_app(app: web.Application, keepalive_timeout=75.0):
await start_app(
app,
keepalive_timeout=keepalive_timeout,
)
while True:
await asyncio.sleep(3600)