fix: use detach() to preserve stdout buffer on teardown#96
Merged
cristipufu merged 1 commit intomainfrom Feb 27, 2026
Merged
Conversation
3981996 to
13e7849
Compare
When stdout uses non-UTF-8 encoding (e.g. cp1252 on Windows piped mode), the interceptor creates a TextIOWrapper around sys.stdout.buffer. Using close() on teardown destroyed the shared buffer, causing ValueError in subsequent stdout writes (e.g. click.echo()). - Replace close() with detach() to disconnect the wrapper without closing the underlying buffer - Reorder teardown: detach utf8_stdout before closing the handler, so StreamHandler.close() cannot cascade a close through the wrapper - Add del to guard against double-teardown (detach is not idempotent) - Bump version to 0.9.2 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
13e7849 to
04562e6
Compare
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.
Summary
ValueErrorwhen writing to stdout after interceptor teardown on Windows piped mode (cp1252 encoding)self.utf8_stdout.close()withself.utf8_stdout.detach()in_interceptor.pyteardown to avoid destroying the sharedsys.stdout.bufferdel self.utf8_stdoutto guard against double-teardown sincedetach()is not idempotentContext
When stdout uses non-UTF-8 encoding (e.g. cp1252 on Windows in piped mode), the interceptor creates a
TextIOWrapperaroundsys.stdout.buffer.close()cascades to close the shared underlying buffer, makingsys.stdoutunusable after teardown.detach()disconnects the wrapper without closing the buffer.Test plan
ValueErrorfromclick.echo()after interceptor teardown🤖 Generated with Claude Code
Development Package