Resolve errors in TeeStream and capture_output#3497
Merged
blnicho merged 8 commits intoPyomo:mainfrom Mar 5, 2025
Merged
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3497 +/- ##
==========================================
- Coverage 88.64% 88.43% -0.21%
==========================================
Files 881 881
Lines 100873 100896 +23
==========================================
- Hits 89421 89230 -191
- Misses 11452 11666 +214
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
blnicho
approved these changes
Mar 5, 2025
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 #3487, partially addresses #3484
Summary/Motivation:
The recent rework of Pyomo's
TeeStream/capture_outputfunctionality to better support highspy inadvertently broke the ability to run within Jupyter notebooks (see #3487). This PR reworks how we manage capturing file descriptors to both avoid the error reported in the issue and to ensure that all output generated withincapture_outputis actually captured and redirected to the intended stream.Additionally, this PR ensures that errors generated within
capture_outputare not themselves suppressed bycapture_outputand instead are allowed to propagate out to the surrounding context. In particularly, this ensures that passing non-TextIOStreamobjects tocapture_outputactually generates (sensible) errors for the user:Changes proposed in this PR:
TeeStreamshouldn't need to open new streams to underlying file descriptorscapture_output(capture_fd=True)should capture up to 4 file descriptors: 1, 2, sys.stdout.fileno(), and sys.stderr.fileno()capture_outputshould NOT capture errors generated withinpyomo.common.teecapture_output, including the output of the exception that triggered the error.Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: