mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Close event loop to avoid error on exiting HASS (#3762)
This commit is contained in:
parent
09cbf68637
commit
fe317b806f
@ -159,11 +159,13 @@ class HomeAssistant(object):
|
|||||||
# Register the async start
|
# Register the async start
|
||||||
self.loop.create_task(self.async_start())
|
self.loop.create_task(self.async_start())
|
||||||
|
|
||||||
|
@callback
|
||||||
def stop_homeassistant(*args):
|
def stop_homeassistant(*args):
|
||||||
"""Stop Home Assistant."""
|
"""Stop Home Assistant."""
|
||||||
self.exit_code = 0
|
self.exit_code = 0
|
||||||
self.async_add_job(self.async_stop)
|
self.async_add_job(self.async_stop)
|
||||||
|
|
||||||
|
@callback
|
||||||
def restart_homeassistant(*args):
|
def restart_homeassistant(*args):
|
||||||
"""Restart Home Assistant."""
|
"""Restart Home Assistant."""
|
||||||
self.exit_code = RESTART_EXIT_CODE
|
self.exit_code = RESTART_EXIT_CODE
|
||||||
@ -205,6 +207,8 @@ class HomeAssistant(object):
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.loop.call_soon(stop_homeassistant)
|
self.loop.call_soon(stop_homeassistant)
|
||||||
self.loop.run_forever()
|
self.loop.run_forever()
|
||||||
|
finally:
|
||||||
|
self.loop.close()
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_start(self):
|
def async_start(self):
|
||||||
|
@ -72,14 +72,14 @@ def get_test_home_assistant(num_threads=None):
|
|||||||
def fake_stop():
|
def fake_stop():
|
||||||
yield None
|
yield None
|
||||||
|
|
||||||
def start_hass():
|
@patch.object(ha, 'async_create_timer')
|
||||||
|
@patch.object(ha, 'async_monitor_worker_pool')
|
||||||
|
@patch.object(hass.loop, 'add_signal_handler')
|
||||||
|
@patch.object(hass.loop, 'run_forever')
|
||||||
|
@patch.object(hass.loop, 'close')
|
||||||
|
@patch.object(hass, 'async_stop', return_value=fake_stop())
|
||||||
|
def start_hass(*mocks):
|
||||||
"""Helper to start hass."""
|
"""Helper to start hass."""
|
||||||
with patch.object(hass.loop, 'run_forever', return_value=None):
|
|
||||||
with patch.object(hass, 'async_stop', return_value=fake_stop()):
|
|
||||||
with patch.object(ha, 'async_create_timer', return_value=None):
|
|
||||||
with patch.object(ha, 'async_monitor_worker_pool',
|
|
||||||
return_value=None):
|
|
||||||
with patch.object(hass.loop, 'add_signal_handler'):
|
|
||||||
orig_start()
|
orig_start()
|
||||||
hass.block_till_done()
|
hass.block_till_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user