fix: check if loop exists

avoids errors if exchange init shuts down before the loop is created

closes #12822
This commit is contained in:
Matthias
2026-02-14 08:11:13 +01:00
parent 67eaa4ac49
commit 05e759a38c

View File

@@ -314,7 +314,10 @@ class Exchange:
if self._exchange_ws: if self._exchange_ws:
self._exchange_ws.cleanup() self._exchange_ws.cleanup()
logger.debug("Exchange object destroyed, closing async loop") logger.debug("Exchange object destroyed, closing async loop")
loop_running = self.loop.is_running() or asyncio.get_event_loop().is_running() loop_running = (
hasattr(self, "loop") and self.loop.is_running()
) or asyncio.get_event_loop().is_running()
if ( if (
getattr(self, "_api_async", None) getattr(self, "_api_async", None)
and inspect.iscoroutinefunction(self._api_async.close) and inspect.iscoroutinefunction(self._api_async.close)