forked from LBRYCommunity/lbry-sdk
[wallet server] improved/stabler signal handlers
This commit is contained in:
parent
3e4c9f25a8
commit
9a9d37cc50
1 changed files with 8 additions and 2 deletions
|
@ -116,10 +116,16 @@ class Server:
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
def __exit():
|
||||||
|
raise SystemExit()
|
||||||
try:
|
try:
|
||||||
loop.add_signal_handler(signal.SIGINT, lambda: asyncio.ensure_future(self.stop()))
|
loop.add_signal_handler(signal.SIGINT, __exit)
|
||||||
loop.add_signal_handler(signal.SIGTERM, lambda: asyncio.ensure_future(self.stop()))
|
loop.add_signal_handler(signal.SIGTERM, __exit)
|
||||||
loop.run_until_complete(self.start())
|
loop.run_until_complete(self.start())
|
||||||
loop.run_until_complete(self.shutdown_event.wait())
|
loop.run_until_complete(self.shutdown_event.wait())
|
||||||
|
except (SystemExit, KeyboardInterrupt):
|
||||||
|
pass
|
||||||
finally:
|
finally:
|
||||||
|
loop.run_until_complete(self.stop())
|
||||||
loop.run_until_complete(loop.shutdown_asyncgens())
|
loop.run_until_complete(loop.shutdown_asyncgens())
|
||||||
|
|
Loading…
Reference in a new issue