Move signal handling out of core to bootstrap (#5815)

* Move signal handling out of core to bootstrap

* Fix tests
This commit is contained in:
Pascal Vizeli
2017-02-09 06:58:45 +01:00
committed by Paulus Schoutsen
parent 7eb4bdc37b
commit 2cbed9cd96
7 changed files with 44 additions and 26 deletions

View File

@@ -11,7 +11,6 @@ import enum
import logging
import os
import re
import signal
import sys
import threading
@@ -26,7 +25,7 @@ from homeassistant.const import (
ATTR_SERVICE_CALL_ID, ATTR_SERVICE_DATA, EVENT_CALL_SERVICE,
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
EVENT_SERVICE_EXECUTED, EVENT_SERVICE_REGISTERED, EVENT_STATE_CHANGED,
EVENT_TIME_CHANGED, MATCH_ALL, RESTART_EXIT_CODE, __version__)
EVENT_TIME_CHANGED, MATCH_ALL, __version__)
from homeassistant.exceptions import (
HomeAssistantError, InvalidEntityFormatError, ShuttingDown)
from homeassistant.util.async import (
@@ -150,24 +149,6 @@ class HomeAssistant(object):
_LOGGER.info("Starting Home Assistant")
self.state = CoreState.starting
# Setup signal handling
if sys.platform != 'win32':
def _async_signal_handle(exit_code):
"""Wrap signal handling."""
self.async_add_job(self.async_stop(exit_code))
try:
self.loop.add_signal_handler(
signal.SIGTERM, _async_signal_handle, 0)
except ValueError:
_LOGGER.warning("Could not bind to SIGTERM")
try:
self.loop.add_signal_handler(
signal.SIGHUP, _async_signal_handle, RESTART_EXIT_CODE)
except ValueError:
_LOGGER.warning("Could not bind to SIGHUP")
# pylint: disable=protected-access
self.loop._thread_ident = threading.get_ident()
_async_create_timer(self)