[wallet server] improved/stabler signal handlers

This commit is contained in:
Victor Shyba 2019-01-24 21:40:24 -03:00 committed by Lex Berezhny
parent 3e4c9f25a8
commit 9a9d37cc50

View file

@ -116,10 +116,16 @@ class Server:
def run(self):
loop = asyncio.get_event_loop()
def __exit():
raise SystemExit()
try:
loop.add_signal_handler(signal.SIGINT, lambda: asyncio.ensure_future(self.stop()))
loop.add_signal_handler(signal.SIGTERM, lambda: asyncio.ensure_future(self.stop()))
loop.add_signal_handler(signal.SIGINT, __exit)
loop.add_signal_handler(signal.SIGTERM, __exit)
loop.run_until_complete(self.start())
loop.run_until_complete(self.shutdown_event.wait())
except (SystemExit, KeyboardInterrupt):
pass
finally:
loop.run_until_complete(self.stop())
loop.run_until_complete(loop.shutdown_asyncgens())