fix: stop logger teardown from closing process stdout#31
Open
raulmol wants to merge 1 commit into
Open
Conversation
setup_logger wraps sys.stdout.buffer in a new TextIOWrapper on every call. After clean_logger removes the RichHandler, the wrapper becomes unreachable and its garbage collection closes the underlying buffer, i.e. the process's real stdout. Any later setup_logger call in the same process (e.g. the organize stage after the setup stage) then raises 'ValueError: I/O operation on closed file'. Share a single module-level console that is created once and never collected, so stdout stays open across logger setup/teardown cycles.
Author
|
@microsoft-github-policy-service agree |
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.
Fixes #30.
setup_loggerwrapssys.stdout.bufferin a newTextIOWrapperper call; afterclean_loggerdrops theRichHandler, garbage collection of that wrapper closes the underlying buffer — the process's real stdout. The nextsetup_loggercall in the same process (organize stage after setup stage) then raisesValueError: I/O operation on closed file, andrun_organize's ownconsole.printcrashes with the same error while reporting it, masking the root cause.Change
launch/utilities/logger.pyonly: create the UTF-8-wrapped richConsoleonce at module level (_get_shared_console) and reuse it for everyRichHandler, so the wrapper is never collected and stdout stays open across logger setup/teardown cycles. Behavior (UTF-8 re-encoding witherrors="replace", soft wrap) is unchanged.Verification
Also verified end-to-end on a private monorepo task: before the fix, the organize stage failed immediately after a successful setup stage with
I/O operation on closed file; with the fix it proceeds into the organize agents.