Extract connection reset from exchange_ws

This commit is contained in:
Matthias
2024-05-31 06:48:38 +02:00
parent 7e736a34dd
commit 33e61b1308

View File

@@ -46,15 +46,24 @@ class ExchangeWS:
for task in self._background_tasks:
task.cancel()
if hasattr(self, "_loop"):
asyncio.run_coroutine_threadsafe(self._cleanup_async(), loop=self._loop)
while not self.__cleanup_called:
time.sleep(0.1)
self.reset_connections()
self._loop.call_soon_threadsafe(self._loop.stop)
self._thread.join()
logger.debug("Stopped")
def reset_connections(self) -> None:
"""
Reset all connections - avoids "connection-reset" errors that happen after ~9 days
"""
if hasattr(self, "_loop"):
logger.info("Resetting WS connections.")
asyncio.run_coroutine_threadsafe(self._cleanup_async(), loop=self._loop)
while not self.__cleanup_called:
time.sleep(0.1)
self.__cleanup_called = False
async def _cleanup_async(self) -> None:
try:
await self.ccxt_object.close()