run-server async
This commit is contained in:
parent
a187cfe9cc
commit
3edb6cf3f2
@ -6,11 +6,23 @@ from v6d0auth.config import port, host
|
||||
from v6d1tokens.app import get_app
|
||||
from v6d1tokens.tdb import TDB
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
async def main():
|
||||
tdb = TDB()
|
||||
loop.run_until_complete(tdb.db.__aenter__())
|
||||
try:
|
||||
web.run_app(get_app(tdb), host=host, port=port, loop=loop)
|
||||
finally:
|
||||
loop.run_until_complete(tdb.db.__aexit__(None, None, None))
|
||||
app = get_app(tdb)
|
||||
async with tdb.db:
|
||||
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))
|
||||
)
|
||||
while True:
|
||||
await asyncio.sleep(3600)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
|
Reference in New Issue
Block a user