From 5afe59f2eb89164e2ba8b843ab6293ef8d30f8fb Mon Sep 17 00:00:00 2001 From: David vonThenen <12752197+dvonthenen@users.noreply.github.com> Date: Tue, 16 Apr 2024 10:41:46 -0700 Subject: [PATCH] Reset Exit Signal. Do Not Delete Event. --- deepgram/clients/live/v1/async_client.py | 10 +++++----- deepgram/clients/live/v1/client.py | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/deepgram/clients/live/v1/async_client.py b/deepgram/clients/live/v1/async_client.py index 31f7f92f..b518f927 100644 --- a/deepgram/clients/live/v1/async_client.py +++ b/deepgram/clients/live/v1/async_client.py @@ -50,7 +50,7 @@ def __init__(self, config: DeepgramClientOptions): self.config = config self.endpoint = "v1/listen" self._socket = None - self._exit_event = None + self._exit_event = asyncio.Event() self._event_handlers = {event: [] for event in LiveTranscriptionEvents} self.websocket_url = convert_to_websocket_url(self.config.url, self.endpoint) @@ -123,7 +123,7 @@ async def start( extra_headers=combined_headers, ping_interval=PING_INTERVAL, ) - self._exit_event = asyncio.Event() + self._exit_event.clear() # listen thread self._listen_thread = asyncio.create_task(self._listening()) @@ -184,7 +184,7 @@ async def _listening(self) -> None: while True: try: - if self._exit_event is not None and self._exit_event.is_set(): + if self._exit_event.is_set(): self.logger.notice("_listening exiting gracefully") self.logger.debug("AsyncLiveClient._listening LEAVE") return @@ -336,7 +336,7 @@ async def _keep_alive(self) -> None: counter += 1 await asyncio.sleep(ONE_SECOND) - if self._exit_event is not None and self._exit_event.is_set(): + if self._exit_event.is_set(): self.logger.notice("_keep_alive exiting gracefully") self.logger.debug("AsyncLiveClient._keep_alive LEAVE") return @@ -409,7 +409,7 @@ async def send(self, data: Union[str, bytes]) -> bool: """ self.logger.spam("AsyncLiveClient.send ENTER") - if self._exit_event is not None and self._exit_event.is_set(): + if self._exit_event.is_set(): self.logger.notice("send exiting gracefully") self.logger.debug("AsyncLiveClient.send LEAVE") return False diff --git a/deepgram/clients/live/v1/client.py b/deepgram/clients/live/v1/client.py index ca5cf6fb..f73f0ccd 100644 --- a/deepgram/clients/live/v1/client.py +++ b/deepgram/clients/live/v1/client.py @@ -52,7 +52,8 @@ def __init__(self, config: DeepgramClientOptions): self.config = config self.endpoint = "v1/listen" self._socket = None - self._exit_event = None + self._exit_event = threading.Event() + self._lock_send = threading.Lock() self._event_handlers = {event: [] for event in LiveTranscriptionEvents} self.websocket_url = convert_to_websocket_url(self.config.url, self.endpoint) @@ -120,8 +121,7 @@ def start( url_with_params = append_query_params(self.websocket_url, combined_options) try: self._socket = connect(url_with_params, additional_headers=combined_headers) - self._exit_event = threading.Event() - self._lock_send = threading.Lock() + self._exit_event.clear() # listening thread self._listen_thread = threading.Thread(target=self._listening) @@ -184,7 +184,7 @@ def _listening(self) -> None: while True: try: - if self._exit_event is not None and self._exit_event.is_set(): + if self._exit_event.is_set(): self.logger.notice("_listening exiting gracefully") self.logger.debug("LiveClient._listening LEAVE") return @@ -336,7 +336,7 @@ def _keep_alive(self) -> None: counter += 1 self._exit_event.wait(timeout=ONE_SECOND) - if self._exit_event is not None and self._exit_event.is_set(): + if self._exit_event.is_set(): self.logger.notice("_keep_alive exiting gracefully") self.logger.debug("LiveClient._keep_alive LEAVE") return @@ -407,7 +407,7 @@ def send(self, data: Union[str, bytes]) -> bool: """ self.logger.spam("LiveClient.send ENTER") - if self._exit_event is not None and self._exit_event.is_set(): + if self._exit_event.is_set(): self.logger.notice("send exiting gracefully") self.logger.debug("AsyncLiveClient.send LEAVE") return False