Closed dvonthenen closed 1 week ago
The AsyncLiveClient
class in async_client.py
was updated to improve thread management and debugging. This includes using the threading
module, changing thread attributes to Union[asyncio.Task, None]
, adding debug statements, and modifying the _emit
method to handle event tasks with asyncio.create_task
and asyncio.gather
.
File Path | Change Summary |
---|---|
deepgram/clients/live/v1/async_client.py |
Updated _listen_thread and _keep_alive_thread to Union[asyncio.Task, None] , added debug statements, and modified _emit method to use asyncio.create_task and asyncio.gather . |
sequenceDiagram
participant Client
participant AsyncLiveClient
participant EventHandler
participant asyncio
Client->>AsyncLiveClient: Initialize
AsyncLiveClient->>AsyncLiveClient: _listen_thread = None
AsyncLiveClient->>AsyncLiveClient: _keep_alive_thread = None
Client->>AsyncLiveClient: Start listening
AsyncLiveClient->>AsyncLiveClient: Create _listen_thread (asyncio.create_task)
AsyncLiveClient->>AsyncLiveClient: Log active threads
Client->>AsyncLiveClient: Keep alive
AsyncLiveClient->>AsyncLiveClient: Create _keep_alive_thread (asyncio.create_task)
AsyncLiveClient->>AsyncLiveClient: Log active threads
Client->>AsyncLiveClient: Emit event
AsyncLiveClient->>EventHandler: Create event handler tasks (asyncio.create_task)
EventHandler->>AsyncLiveClient: Return task
AsyncLiveClient->>asyncio: Gather tasks (asyncio.gather)
asyncio->>AsyncLiveClient: Return results
AsyncLiveClient->>Client: Event handled
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?
Proposed changes
Addresses: https://github.com/deepgram/deepgram-python-sdk/issues/408, https://github.com/deepgram/deepgram-python-sdk/issues/409
This PR:
AsyncLiveClient
andLiveClient
to keep track of threadsAsyncLiveClient._emit
, we want to wait for all the callbacks to complete before exiting_emit
. This isn't a bug, provided the user doesn't have a callback function that doesn't hang.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