diff --git a/src/fastcs/backend.py b/src/fastcs/backend.py index 3ec893a..572ff96 100644 --- a/src/fastcs/backend.py +++ b/src/fastcs/backend.py @@ -53,10 +53,18 @@ def _run_initial_tasks(self): future.result() def _start_scan_tasks(self): - scan_tasks = _get_scan_tasks(self._mapping) - - for task in scan_tasks: - asyncio.run_coroutine_threadsafe(task(), self._loop) + async def run_tasks(): + futures = [task() for task in _get_scan_tasks(self._mapping)] + for future in asyncio.as_completed(futures): + try: + await future + except Exception as e: + # We don't exit the ioc when a scan loop errors, + # but we do print the information. + print(f"Scan loop stopped with exception:\n {e}") + raise e + + asyncio.run_coroutine_threadsafe(run_tasks(), self._loop) def _run(self): raise NotImplementedError("Specific Backend must implement _run")