Close event loop to avoid error on exiting HASS (#3762)
parent
09cbf68637
commit
fe317b806f
|
@ -159,11 +159,13 @@ class HomeAssistant(object):
|
|||
# Register the async start
|
||||
self.loop.create_task(self.async_start())
|
||||
|
||||
@callback
|
||||
def stop_homeassistant(*args):
|
||||
"""Stop Home Assistant."""
|
||||
self.exit_code = 0
|
||||
self.async_add_job(self.async_stop)
|
||||
|
||||
@callback
|
||||
def restart_homeassistant(*args):
|
||||
"""Restart Home Assistant."""
|
||||
self.exit_code = RESTART_EXIT_CODE
|
||||
|
@ -205,6 +207,8 @@ class HomeAssistant(object):
|
|||
except KeyboardInterrupt:
|
||||
self.loop.call_soon(stop_homeassistant)
|
||||
self.loop.run_forever()
|
||||
finally:
|
||||
self.loop.close()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_start(self):
|
||||
|
|
|
@ -72,16 +72,16 @@ def get_test_home_assistant(num_threads=None):
|
|||
def fake_stop():
|
||||
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."""
|
||||
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()
|
||||
hass.block_till_done()
|
||||
orig_start()
|
||||
hass.block_till_done()
|
||||
|
||||
def stop_hass():
|
||||
orig_stop()
|
||||
|
|
Loading…
Reference in New Issue