Skip to content

Commit b52c70d

Browse files
Merge pull request #372 from dvonthenen/dont-set-obj-threads-to-none
Don't Set Thread References to None
2 parents 10204e8 + 9d7f800 commit b52c70d

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

deepgram/clients/live/v1/async_client.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ async def _listening(self) -> None:
283283
return
284284

285285
except websockets.exceptions.WebSocketException as e:
286+
if e.code == 1000:
287+
self.logger.notice(f"_listening({e.code}) exiting gracefully")
288+
self.logger.debug("AsyncLiveClient._listening LEAVE")
289+
return
290+
286291
self.logger.error(
287292
"WebSocketException in AsyncLiveClient._listening: %s", e
288293
)
@@ -357,6 +362,11 @@ async def _keep_alive(self) -> None:
357362
return
358363

359364
except websockets.exceptions.WebSocketException as e:
365+
if e.code == 1000:
366+
self.logger.notice(f"_keep_alive({e.code}) exiting gracefully")
367+
self.logger.debug("AsyncLiveClient._keep_alive LEAVE")
368+
return
369+
360370
self.logger.error(
361371
"WebSocketException in AsyncLiveClient._keep_alive: %s", e
362372
)
@@ -419,11 +429,18 @@ async def send(self, data: Union[str, bytes]) -> bool:
419429
await self._socket.send(data)
420430
except websockets.exceptions.ConnectionClosedOK as e:
421431
self.logger.notice(f"send() exiting gracefully: {e.code}")
422-
self.logger.debug("AsyncLiveClient._keep_alive LEAVE")
432+
self.logger.debug("AsyncLiveClient.send LEAVE")
423433
if self.config.options.get("termination_exception_send") == "true":
424434
raise
425435
return True
426436
except websockets.exceptions.WebSocketException as e:
437+
if e.code == 1000:
438+
self.logger.notice(f"send({e.code}) exiting gracefully")
439+
self.logger.debug("AsyncLiveClient.send LEAVE")
440+
if self.config.options.get("termination_exception_send") == "true":
441+
raise
442+
return True
443+
427444
self.logger.error("send() failed - WebSocketException: %s", str(e))
428445
self.logger.spam("AsyncLiveClient.send LEAVE")
429446
if self.config.options.get("termination_exception_send") == "true":
@@ -469,8 +486,6 @@ async def finish(self) -> bool:
469486
# Use asyncio.gather to wait for tasks to be cancelled
470487
await asyncio.gather(*filter(None, tasks), return_exceptions=True)
471488
self.logger.notice("threads joined")
472-
self._listen_thread = None
473-
self._keep_alive_thread = None
474489

475490
self._socket = None
476491

deepgram/clients/live/v1/client.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def start(
129129

130130
# keepalive thread
131131
if self.config.options.get("keepalive") == "true":
132-
self.logger.notice("keepalive is disabled")
132+
self.logger.notice("keepalive is enabled")
133133
self._keep_alive_thread = threading.Thread(target=self._keep_alive)
134134
self._keep_alive_thread.start()
135135
else:
@@ -283,6 +283,11 @@ def _listening(self) -> None:
283283
return
284284

285285
except websockets.exceptions.WebSocketException as e:
286+
if e.code == 1000:
287+
self.logger.notice(f"_listening({e.code}) exiting gracefully")
288+
self.logger.debug("LiveClient._listening LEAVE")
289+
return
290+
286291
self.logger.error(
287292
"WebSocketException in AsyncLiveClient._listening: %s", e
288293
)
@@ -357,6 +362,11 @@ def _keep_alive(self) -> None:
357362
return
358363

359364
except websockets.exceptions.WebSocketException as e:
365+
if e.code == 1000:
366+
self.logger.notice(f"_keep_alive({e.code}) exiting gracefully")
367+
self.logger.debug("LiveClient._keep_alive LEAVE")
368+
return
369+
360370
self.logger.error(
361371
"WebSocketException in AsyncLiveClient._keep_alive: %s", e
362372
)
@@ -423,6 +433,15 @@ def send(self, data: Union[str, bytes]) -> bool:
423433
raise
424434
return True
425435
except websockets.exceptions.WebSocketException as e:
436+
if e.code == 1000:
437+
self.logger.notice(f"send({e.code}) exiting gracefully")
438+
self.logger.debug("LiveClient.send LEAVE")
439+
if (
440+
self.config.options.get("termination_exception_send")
441+
== "true"
442+
):
443+
raise
444+
return True
426445
self.logger.error("send() failed - WebSocketException: %s", str(e))
427446
self.logger.spam("LiveClient.send LEAVE")
428447
if self.config.options.get("termination_exception_send") == "true":
@@ -457,12 +476,10 @@ def finish(self) -> bool:
457476
self.logger.verbose("cancelling tasks...")
458477
if self._keep_alive_thread is not None:
459478
self._keep_alive_thread.join()
460-
self._keep_alive_thread = None
461479
self.logger.notice("processing thread joined")
462480

463481
if self._listen_thread is not None:
464482
self._listen_thread.join()
465-
self._listen_thread = None
466483
self.logger.notice("listening thread joined")
467484

468485
self._socket = None

0 commit comments

Comments
 (0)