Skip to content

Commit

Permalink
Shut down the logging system when the runner finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Oct 4, 2017
1 parent b7cde87 commit 1c98be8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion asphalt/core/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from asyncio.events import AbstractEventLoop
from concurrent.futures import ThreadPoolExecutor
from logging import basicConfig, getLogger, INFO, Logger
from logging import basicConfig, getLogger, INFO, Logger, shutdown
from logging.config import dictConfig
from typing import Union, Dict, Any

Expand Down Expand Up @@ -156,5 +156,8 @@ def run_application(component: Union[Component, Dict[str, Any]], *, event_loop_p
event_loop.close()
logger.info('Application stopped')

# Shut down the logging system
shutdown()

if exit_code:
sys.exit(exit_code)
4 changes: 4 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Version history

This library adheres to `Semantic Versioning <http://semver.org/>`_.

**4.3.0**

- The runner now calls ``logging.shutdown()`` after the event loop has been closed

**4.2.0** (2017-08-24)

- Allowed selecting the service to run with ``asphalt run`` using an environment variable
Expand Down
5 changes: 5 additions & 0 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ async def run(self, ctx: Context):
return 20


@pytest.fixture(autouse=True)
def prevent_logging_shutdown(monkeypatch):
monkeypatch.setattr('asphalt.core.runner.shutdown', lambda: None)


def test_sigterm_handler_loop_not_running(event_loop):
"""Test that the SIGTERM handler does nothing if the event loop is not running."""
sigterm_handler(logging.getLogger(__name__), event_loop)
Expand Down

0 comments on commit 1c98be8

Please sign in to comment.