refactor(tos): add context manager support and proper resource cleanup for TOSService - #164
Open
zhangning-agent wants to merge 2 commits into
Open
refactor(tos): add context manager support and proper resource cleanup for TOSService#164zhangning-agent wants to merge 2 commits into
zhangning-agent wants to merge 2 commits into
Conversation
1. add close() method to TOSService to release client connections 2. implement __enter__ and __exit__ for context manager usage 3. update VeCPCRBuilder to use context manager for TOSService and add finally block for cleanup 4. add unit tests for TOSService resource management 5. update existing tests to verify close() method is called
…try-finally cleanup across CLI tools
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 adds context manager (
__enter__/__exit__) support and aclose()method toTOSService, ensuring underlying TOS client connections and sockets are properly released upon exit.Key Changes
TOSServiceImprovements:close()method with idempotency protection (self.client = None).__enter__and__exit__context manager protocol.__del__finalizer in favor of deterministic resource management.VeCPCRBuilderUsage:VeCPCRBuilder._upload_to_tosto instantiateTOSServiceviawith TOSService(...) as tos_service:block.tests/toolkit/volcengine/test_tos_service.pyto verifyclose()and context manager behavior.tests/toolkit/builders/test_ve_pipeline_upload_tos.pyto assertclose()is called on exit.Testing
Ran pytest suite locally:
tests/toolkit/builders/test_ve_pipeline_upload_tos.pytests/toolkit/volcengine/test_tos_service.pyResult: 12 passed cleanly.