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.app import get_app
|
||||||
from v6d1tokens.tdb import TDB
|
from v6d1tokens.tdb import TDB
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
loop = asyncio.get_event_loop()
|
async def main():
|
||||||
tdb = TDB()
|
tdb = TDB()
|
||||||
loop.run_until_complete(tdb.db.__aenter__())
|
app = get_app(tdb)
|
||||||
try:
|
async with tdb.db:
|
||||||
web.run_app(get_app(tdb), host=host, port=port, loop=loop)
|
runner = web.AppRunner(app)
|
||||||
finally:
|
await runner.setup()
|
||||||
loop.run_until_complete(tdb.db.__aexit__(None, None, None))
|
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