deepgram-python-sdk icon indicating copy to clipboard operation
deepgram-python-sdk copied to clipboard

Getting "Tasks cancelled error:" when finishing a connection

Open jcbjoe opened this issue 10 months ago • 4 comments

What is the current behavior?

When you call the finish function on AsyncListenWebSocketClient I get an error which says "tasks cancelled error:"

Steps to reproduce

Start transcribing then call the finish function on the client

Expected behavior

The finish function should return True and end gracefully

Please tell us about your environment

We want to make sure the problem isn't specific to your operating system or programming language.

  • Operating System/Version: MacOS 15.1.1
  • Python Version: 3.11.5
  • **deepgram-sdk version: 3.8.0

Other information

I have gone through the code and found where the error is coming from, it on line 545 in clients/listen/v1/websocket/async_client.py await asyncio.wait_for(asyncio.gather(*tasks), timeout=10) Its awaiting the _keep_alive_thread however a few lines before the task is canceled. Due to this wait_for will always fail as the task is canceled.

            if self._keep_alive_thread is not None:
                self._keep_alive_thread.cancel()
                tasks.append(self._keep_alive_thread)
                self._logger.notice("processing _keep_alive_thread cancel...")

jcbjoe avatar Feb 01 '25 00:02 jcbjoe

Hey @jpvajda, what should be the next step in order to fix this bug? Ideally, it should know if the asyncio.CancelledError was an effect of a deliberate attempt to finish the websocket client (e.g. during hangup, in the case of voice agent)

In such cases, this is not an error and it should be returned True. or the log should not point it as error. Let me know if there is some gap in the understanding

nilinswap avatar Mar 18 '25 21:03 nilinswap

I have exactly the same problem. It is a really bad practice to log an error when everything is fine & the function returning True. What is the point of that? Why not to use info instead?

Operating System/Version: MacOS 15.2 Python Version: 3.10.13 deepgram-sdk version: 3.10.1

obo-cell avatar Mar 31 '25 08:03 obo-cell

is there any action being taken on this to fix this issue?

shekhar-zenafide avatar Jul 08 '25 07:07 shekhar-zenafide

Just an update, #550 has been merged to fix this issue and will go out in our next Python SDK release

jpvajda avatar Jul 15 '25 19:07 jpvajda