diff --git a/deepgram/clients/common/v1/abstract_async_websocket.py b/deepgram/clients/common/v1/abstract_async_websocket.py index c6a75193..2cb9fb13 100644 --- a/deepgram/clients/common/v1/abstract_async_websocket.py +++ b/deepgram/clients/common/v1/abstract_async_websocket.py @@ -254,12 +254,18 @@ async def _listening(self) -> None: self._logger.debug("AbstractAsyncWebSocketClient._listening LEAVE") except websockets.exceptions.ConnectionClosedOK as e: + # signal exit and close + await self._signal_exit() + self._logger.notice(f"_listening({e.code}) exiting gracefully") self._logger.debug("AbstractAsyncWebSocketClient._listening LEAVE") return except websockets.exceptions.ConnectionClosed as e: if e.code in [1000, 1001]: + # signal exit and close + await self._signal_exit() + self._logger.notice(f"_listening({e.code}) exiting gracefully") self._logger.debug("AbstractAsyncWebSocketClient._listening LEAVE") return @@ -466,7 +472,7 @@ async def finish(self) -> bool: except asyncio.CancelledError as e: self._logger.error("tasks cancelled error: %s", e) self._logger.debug("AbstractAsyncWebSocketClient.finish LEAVE") - return False + return True async def _signal_exit(self) -> None: # send close event diff --git a/deepgram/clients/common/v1/abstract_sync_websocket.py b/deepgram/clients/common/v1/abstract_sync_websocket.py index 4e796a90..75c6ab71 100644 --- a/deepgram/clients/common/v1/abstract_sync_websocket.py +++ b/deepgram/clients/common/v1/abstract_sync_websocket.py @@ -256,12 +256,18 @@ def _listening( self._logger.debug("AbstractSyncWebSocketClient._listening LEAVE") except websockets.exceptions.ConnectionClosedOK as e: + # signal exit and close + self._signal_exit() + self._logger.notice(f"_listening({e.code}) exiting gracefully") self._logger.debug("AbstractSyncWebSocketClient._listening LEAVE") return except websockets.exceptions.ConnectionClosed as e: if e.code in [1000, 1001]: + # signal exit and close + self._signal_exit() + self._logger.notice(f"_listening({e.code}) exiting gracefully") self._logger.debug("AbstractSyncWebSocketClient._listening LEAVE") return