From a41b66bb94ee8be5e8f02b2910a4221f535d7acb Mon Sep 17 00:00:00 2001 From: Ryan Kraus Date: Fri, 29 Jan 2016 22:02:39 -0500 Subject: [PATCH] Cleaned up block_till_stop in core.py 1. Removed handling of KeyboardInterrupt. This will no longer happen now that HASS is run in a subprocess. The KeyboardInterrupt will not be sent to the parent process which will send a SIGTERM to the HASS process. 2. Fixed logger warning about not being able to bind to SIGTERM. 3. Removed check for Windows OSs when binding to SIGTERM. This check was originally put in place when HASS was binding to SIGQUIT. SIGTERM exists in NT OSs, so the check is no longer required. 3. Now returning exit code of 100 when requesting a restart. This will allow the parent process to only restart HASS if it is specifically requested and not just on any encountered crash. --- homeassistant/core.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index e6b0a6ec722..eaaecfe87ee 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -48,6 +48,9 @@ _LOGGER = logging.getLogger(__name__) # Temporary to support deprecated methods _MockHA = namedtuple("MockHomeAssistant", ['bus']) +# The exit code to send to request a restart +RESTART_EXIT_CODE = 100 + class HomeAssistant(object): """Root object of the Home Assistant home automation.""" @@ -87,21 +90,17 @@ class HomeAssistant(object): self.services.register( DOMAIN, SERVICE_HOMEASSISTANT_RESTART, restart_homeassistant) - if os.name != "nt": - try: - signal.signal(signal.SIGTERM, stop_homeassistant) - except ValueError: - _LOGGER.warning( - 'Could not bind to SIGQUIT. Are you running in a thread?') + try: + signal.signal(signal.SIGTERM, stop_homeassistant) + except ValueError: + _LOGGER.warning( + 'Could not bind to SIGTERM. Are you running in a thread?') while not request_shutdown.isSet(): - try: - time.sleep(1) - except KeyboardInterrupt: - break + time.sleep(1) self.stop() - return request_restart.isSet() + return RESTART_EXIT_CODE if request_restart.isSet() else 0 def stop(self): """Stop Home Assistant and shuts down all threads."""