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.pull/1012/head
parent
3534c975f3
commit
a41b66bb94
|
@ -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."""
|
||||
|
|
Loading…
Reference in New Issue