1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Fix Windows loop (#16737)

* Fix Windows loop

* Fix windows Ctrl+C

* Move windows restart handler out of setup_and_run_hass
This commit is contained in:
Paulus Schoutsen
2018-09-22 09:54:37 +02:00
committed by GitHub
parent e9c7fe184d
commit 5613816476
3 changed files with 50 additions and 22 deletions

View File

@@ -43,3 +43,28 @@ def async_register_signal_handling(hass: HomeAssistant) -> None:
signal.SIGHUP, async_signal_handle, RESTART_EXIT_CODE)
except ValueError:
_LOGGER.warning("Could not bind to SIGHUP")
else:
old_sigterm = None
old_sigint = None
@callback
def async_signal_handle(exit_code, frame):
"""Wrap signal handling.
* queue call to shutdown task
* re-instate default handler
"""
signal.signal(signal.SIGTERM, old_sigterm)
signal.signal(signal.SIGINT, old_sigint)
hass.async_create_task(hass.async_stop(exit_code))
try:
old_sigterm = signal.signal(signal.SIGTERM, async_signal_handle)
except ValueError:
_LOGGER.warning("Could not bind to SIGTERM")
try:
old_sigint = signal.signal(signal.SIGINT, async_signal_handle)
except ValueError:
_LOGGER.warning("Could not bind to SIGINT")