From a7a839526c68659465f24af731ebd380c67d34b0 Mon Sep 17 00:00:00 2001 From: Jason Maldonis Date: Tue, 1 Aug 2023 09:31:52 -0500 Subject: [PATCH] fixed a bug where the streaming websocket was closed and marked as completed before the message queue was cleared --- deepgram/transcription.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deepgram/transcription.py b/deepgram/transcription.py index 6caee1ef..a0427f1e 100644 --- a/deepgram/transcription.py +++ b/deepgram/transcription.py @@ -5,6 +5,7 @@ from enum import Enum from warnings import warn import websockets.client +import websockets.exceptions from ._types import (Options, PrerecordedOptions, LiveOptions, ToggleConfigOptions, TranscriptionSource, PrerecordedTranscriptionResponse, LiveTranscriptionResponse, Metadata, EventHandler) @@ -239,7 +240,8 @@ async def _receiver(self) -> None: try: body = await self._socket.recv() self._queue.put_nowait((True, body)) - except Exception as exc: + except websockets.exceptions.ConnectionClosedOK: + await self._queue.join() self.done = True # socket closed, will terminate on next loop def _ping_handlers(self, event_type: LiveTranscriptionEvent,