Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR improves the client shutdown and termination logic to ensure reliable resource cleanup.
Previously, the shutdown sequence relied on internal flags (
is_initialized,is_connected) that might not update fast enough when managed via a fast-paced UI (e.g., Streamlit). This caused the client to remain active in the background or hang for 10 seconds due torecv_tasknot being cancelled correctly.Removing explicit exceptions makes resource cleanup idempotent. In an asynchronous environment, a shutdown signal can arrive at any stage, even during partial initialization. By allowing methods to return normally rather than throwing errors, we ensure that the cleanup chain is not interrupted. This allows the library to always release resources (sockets and tasks) without leaving “zombies” running in the background.
Key changes:
terminateanddisconnectidempotent by checking for object existence instead of volatile flags.recv_taskis explicitly cancelled and awaited before closing the connection.Type of change
How Has This Been Tested?
The changes were tested using a Streamlit-based management UI by rapidly toggling the bot's state.
ConnectionErrororAttributeErroris raised ifstop()is called before the client is fully initialized.Test Configuration
Checklist