From 1ed38fff6f530a61c50b1cc4a026e0658fc996f0 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Sat, 26 Oct 2019 13:33:43 -0400 Subject: [PATCH] removed runner.shutdown() as runner.cleanup() calls this already --- lbry/lbry/extras/cli.py | 1 + lbry/lbry/extras/daemon/Daemon.py | 7 +------ lbry/lbry/extras/daemon/loggly_handler.py | 6 +++++- lbry/tests/integration/test_cli.py | 5 ++--- lbry/tests/unit/test_cli.py | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lbry/lbry/extras/cli.py b/lbry/lbry/extras/cli.py index 4403832af..46078f285 100644 --- a/lbry/lbry/extras/cli.py +++ b/lbry/lbry/extras/cli.py @@ -276,6 +276,7 @@ def run_daemon(args: argparse.Namespace, conf: Config): pass finally: loop.run_until_complete(daemon.stop()) + logging.shutdown() if hasattr(loop, 'shutdown_asyncgens'): loop.run_until_complete(loop.shutdown_asyncgens()) diff --git a/lbry/lbry/extras/daemon/Daemon.py b/lbry/lbry/extras/daemon/Daemon.py index f54932ab7..1855179a8 100644 --- a/lbry/lbry/extras/daemon/Daemon.py +++ b/lbry/lbry/extras/daemon/Daemon.py @@ -466,18 +466,13 @@ class Daemon(metaclass=JSONRPCServerType): self.component_startup_task = asyncio.create_task(self.component_manager.start()) await self.component_startup_task - async def stop(self, shutdown_runner=True): + async def stop(self): if self.component_startup_task is not None: if self.component_startup_task.done(): await self.component_manager.stop() else: self.component_startup_task.cancel() log.info("stopped api components") - if shutdown_runner: - self.rpc_runner.app.on_shutdown.freeze() - self.streaming_runner.app.on_shutdown.freeze() - await self.rpc_runner.shutdown() - await self.streaming_runner.shutdown() await self.rpc_runner.cleanup() await self.streaming_runner.cleanup() log.info("stopped api server") diff --git a/lbry/lbry/extras/daemon/loggly_handler.py b/lbry/lbry/extras/daemon/loggly_handler.py index 505e83d5f..896507f0a 100644 --- a/lbry/lbry/extras/daemon/loggly_handler.py +++ b/lbry/lbry/extras/daemon/loggly_handler.py @@ -69,7 +69,11 @@ class HTTPSLogglyHandler(logging.Handler): def close(self): super().close() - asyncio.create_task(self._session.close()) + try: + loop = asyncio.get_event_loop() + loop.run_until_complete(self._session.close()) + except RuntimeError: + pass def get_loggly_handler(): diff --git a/lbry/tests/integration/test_cli.py b/lbry/tests/integration/test_cli.py index 6952c9d7e..5ccba81d2 100644 --- a/lbry/tests/integration/test_cli.py +++ b/lbry/tests/integration/test_cli.py @@ -11,6 +11,7 @@ from lbry.extras.daemon.Components import ( ) from lbry.extras.daemon.Daemon import Daemon + class CLIIntegrationTest(AsyncioTestCase): async def asyncSetUp(self): @@ -26,9 +27,7 @@ class CLIIntegrationTest(AsyncioTestCase): Daemon.component_attributes = {} self.daemon = Daemon(conf) await self.daemon.start() - - async def asyncTearDown(self): - await self.daemon.stop(shutdown_runner=False) + self.addCleanup(self.daemon.stop) def test_cli_status_command_with_auth(self): actual_output = StringIO() diff --git a/lbry/tests/unit/test_cli.py b/lbry/tests/unit/test_cli.py index 7abf2dcb6..b7fbdc0de 100644 --- a/lbry/tests/unit/test_cli.py +++ b/lbry/tests/unit/test_cli.py @@ -5,9 +5,9 @@ import contextlib import logging from io import StringIO from unittest import TestCase +from unittest.mock import patch from types import SimpleNamespace from contextlib import asynccontextmanager -from unittest.mock import patch import docopt from torba.testcase import AsyncioTestCase