Extract connection reset from exchange_ws
This commit is contained in:
@@ -46,15 +46,24 @@ class ExchangeWS:
|
|||||||
for task in self._background_tasks:
|
for task in self._background_tasks:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
if hasattr(self, "_loop"):
|
if hasattr(self, "_loop"):
|
||||||
asyncio.run_coroutine_threadsafe(self._cleanup_async(), loop=self._loop)
|
self.reset_connections()
|
||||||
while not self.__cleanup_called:
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
self._loop.call_soon_threadsafe(self._loop.stop)
|
self._loop.call_soon_threadsafe(self._loop.stop)
|
||||||
|
|
||||||
self._thread.join()
|
self._thread.join()
|
||||||
logger.debug("Stopped")
|
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:
|
async def _cleanup_async(self) -> None:
|
||||||
try:
|
try:
|
||||||
await self.ccxt_object.close()
|
await self.ccxt_object.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user