Skip to content

Fix capture_output management of logger file descriptors #3633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 17, 2025

Conversation

jsiirola
Copy link
Member

@jsiirola jsiirola commented Jun 16, 2025

Fixes #3210 .

Summary/Motivation:

This resolves an issue with how capture_output manages LogHandlers when they appear in LogStreams that capture_output is sending output to, as reported by #3210. The root cause was a subtle interaction between Pyomo's default log handler (an instance of pyomo.common.log.StdoutHandler) and the log handler interception used by capture_output. In that situation, the default Pyomo LogHandler was resetting the handler's stream attribute back to the current value of sys.stdout when records were emitted by the handler. This led to capture_output trying to fetch and close the wrong file descriptor on exit.

This PR makes several changes to resolve this situation

  • Update the Redirector classes used by capture_output to explicitly store the file descriptors they open and not rely on the stream to store the fd for them.
  • Update the StdoutHandler class to not permanently change the output stream within the emit / flush methods.
  • Switch Pyomo to not use the StdoutHandler and instead now just use a standard streamHndler.
  • Update online docs so that modules can define a doctest setup functio that will be called for all documentation generated by autosummary.

Changes proposed in this PR:

  • (see above)

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:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Copy link

codecov bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.92%. Comparing base (dc503c2) to head (1922d28).
Report is 14 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3633   +/-   ##
=======================================
  Coverage   88.92%   88.92%           
=======================================
  Files         888      888           
  Lines      102347   102363   +16     
=======================================
+ Hits        91009    91026   +17     
+ Misses      11338    11337    -1     
Flag Coverage Δ
builders 26.68% <14.28%> (-0.01%) ⬇️
default 85.51% <92.85%> (?)
expensive 34.04% <14.28%> (?)
linux 86.73% <100.00%> (-1.95%) ⬇️
linux_other 86.73% <100.00%> (+<0.01%) ⬆️
osx 83.03% <100.00%> (+<0.01%) ⬆️
win 84.94% <100.00%> (+<0.01%) ⬆️
win_other 84.94% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mrmundt mrmundt merged commit 339d1e7 into Pyomo:main Jun 17, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Capture Highs output when solving
2 participants