Closed davidvonthenen closed 3 weeks ago
The changes involve modifications to the AbstractAsyncWebSocketClient
and AbstractSyncWebSocketClient
classes in their respective files. A new method, _signal_exit
, is introduced to handle WebSocket connection closures and manage the exit of listening threads. The _listening
method in both classes is updated to call _signal_exit
upon encountering specific connection closure exceptions. Additionally, the finish
method in the async client is adjusted to always return True
after handling a CancelledError
, streamlining its return logic.
File Path | Change Summary |
---|---|
deepgram/clients/common/v1/abstract_async_websocket.py | Added _signal_exit method for handling WebSocket closure; updated _listening to call _signal_exit on connection closure exceptions; modified finish to always return True after handling CancelledError . |
deepgram/clients/common/v1/abstract_sync_websocket.py | Enhanced _listening method to call _signal_exit on ConnectionClosedOK and ConnectionClosed exceptions for improved error handling during connection closures. |
sequenceDiagram
participant Client as WebSocket Client
participant Server as WebSocket Server
participant Exit as Exit Handler
Client->>Server: Establish Connection
Client->>Client: Start Listening
alt Connection Closed
Client->>Exit: _signal_exit()
Exit->>Server: Close Connection
Exit->>Client: Cleanup Resources
end
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Ab
Proposed changes
Addresses: https://github.com/deepgram/deepgram-python-sdk/issues/477
Should close websocket when server forces disconnect (when not using keepalive and not sending audio).
Types of changes
What types of changes does your code introduce to the community Python SDK? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
NA
Summary by CodeRabbit