Skip to content

Commit

Permalink
Merge pull request #366 from dvonthenen/fix-signal-exit
Browse files Browse the repository at this point in the history
Reset Exit Signal. Do Not Delete Signal.
  • Loading branch information
davidvonthenen authored Apr 16, 2024
2 parents 7461d02 + 5afe59f commit d7b113c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions deepgram/clients/live/v1/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions deepgram/clients/live/v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d7b113c

Please sign in to comment.