Skip to content

Commit

Permalink
supervisor: Log exceptions during interface startup and shutdown grac…
Browse files Browse the repository at this point in the history
…efully in this case
  • Loading branch information
mhthies committed Nov 20, 2023
1 parent 393b65b commit 5c8aac1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions shc/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,25 @@ async def interface_failure(interface_name: str = "n/a") -> None:
asyncio.create_task(stop())


async def _start_interface(interface: AbstractInterface) -> None:
try:
await interface.start()
except Exception as e:
logger.critical("Exception while starting interface %s:", repr(interface), exc_info=e)
raise RuntimeError()


async def run():
_SHC_STOPPED.clear()
logger.info("Starting up interfaces ...")
# TODO catch errors and stop() in case of an exception
await asyncio.gather(*(interface.start() for interface in _REGISTERED_INTERFACES))
try:
await asyncio.gather(*(_start_interface(interface) for interface in _REGISTERED_INTERFACES))
except RuntimeError:
logger.warning("Shutting down SHC due to error while starting up interfaces.")
await stop()
global _EXIT_CODE
_EXIT_CODE = 1
return
logger.info("All interfaces started successfully. Initializing variables ...")
await read_initialize_variables()
logger.info("Variables initialized successfully. Starting timers ...")
Expand Down

0 comments on commit 5c8aac1

Please sign in to comment.