-
Notifications
You must be signed in to change notification settings - Fork 93
Description
In AsyncLiveClient
, the following code snippet checks if the keepalive option is set to true
:
deepgram-python-sdk/deepgram/clients/live/v1/async_client.py
Lines 292 to 297 in 2d0ddf1
if ( | |
counter % DEEPGRAM_INTERVAL == 0 | |
and self.config.options.get("keepalive") == "true" | |
): | |
self.logger.verbose("Sending KeepAlive...") | |
await self.send(json.dumps({"type": "KeepAlive"})) |
However, even if keepalive
is not set in the options, or set to something other than true
, the _keep_alive_thread
is still created.
self._keep_alive_thread = asyncio.create_task(self._keep_alive()) |
Now, if the _keep_alive_thread
exits for some reason, an exception is thrown that can not be handled.
This was causing a problem in v3.1.5
as the following would throw an error if the socket connection closed, even if _keep_alive
was not set to true
.
await self._socket.ping() |
Even in the newer versions, if there is an exception raised from this _keep_alive_thread
coroutine, there's no way to handle the exception and it will flood the user's logs with
Task exception was never retrieved
future: <Task finished name='Task-277' coro=<AsyncLiveClient._keep_alive() done, defined at /usr/local/lib/python3.12/dist-packages/deepgram/clients/live/v1/async_client.py:228> exception="...">
Traceback (most recent call last):
...
Also, if keepalive
is not set to true in options, it's possible to avoid running a coroutine with while True
. Is it possible for you to check the DeepgramClientOptions
before creating the _keep_alive_thread
coroutine, or is there something I'm missing?