chore: harden ws stop cleanup

This commit is contained in:
Matthias
2026-04-24 06:37:05 +02:00
parent f9be1ac82c
commit 05c3360892
+7 -2
View File
@@ -157,16 +157,21 @@ class ExchangeWS:
def _continuous_stopped( def _continuous_stopped(
self, task: asyncio.Task, pair: str, timeframe: str, candle_type: CandleType self, task: asyncio.Task, pair: str, timeframe: str, candle_type: CandleType
): ) -> None:
self._background_tasks.discard(task) self._background_tasks.discard(task)
result = "done" result = "done"
try:
if task.cancelled(): if task.cancelled():
result = "cancelled" result = "cancelled"
else: else:
if (result1 := task.result()) is not None: if (result1 := task.result()) is not None:
result = str(result1) result = str(result1)
except Exception:
result = "error"
logger.exception(f"Unhandled exception in watch task callback for {pair}, {timeframe}")
finally:
logger.info(f"{pair}, {timeframe}, {candle_type} - Task finished - {result}") logger.info(f"{pair}, {timeframe}, {candle_type} - Task finished - {result}")
if hasattr(self, "_loop") and not self._loop.is_closed():
asyncio.run_coroutine_threadsafe( asyncio.run_coroutine_threadsafe(
self._unwatch_ohlcv(pair, timeframe, candle_type), loop=self._loop self._unwatch_ohlcv(pair, timeframe, candle_type), loop=self._loop
) )