From 21ca4f60f7b0c0cb89d0e357af795e32badc2e3c Mon Sep 17 00:00:00 2001 From: hackrush Date: Thu, 14 Feb 2019 00:32:55 +0530 Subject: [PATCH] Stop the daemon on calling `lbrynet stop` --- lbrynet/extras/cli.py | 2 +- lbrynet/extras/daemon/Daemon.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lbrynet/extras/cli.py b/lbrynet/extras/cli.py index e5aa3edcd..6a67b2515 100644 --- a/lbrynet/extras/cli.py +++ b/lbrynet/extras/cli.py @@ -274,7 +274,7 @@ def main(argv=None): daemon = Daemon(conf) try: loop.run_until_complete(daemon.start()) - loop.run_forever() + loop.run_until_complete(daemon.stop_event.wait()) except (GracefulExit, KeyboardInterrupt): pass finally: diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index f3cabf057..ff5500b2a 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -257,6 +257,7 @@ class Daemon(metaclass=JSONRPCServerType): ) self.component_startup_task = None self._connection_status: typing.Tuple[float, bool] = [self.component_manager.loop.time(), False] + self.stop_event = asyncio.Event() logging.getLogger('aiohttp.access').setLevel(logging.WARN) app = web.Application() @@ -604,6 +605,7 @@ class Daemon(metaclass=JSONRPCServerType): (string) Shutdown message """ log.info("Shutting down lbrynet daemon") + self.stop_event.set() return "Shutting down" async def jsonrpc_status(self):