Skip to content
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

Resolve OSX error accessing closed filehandle #3467

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyomo/common/tee.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def __init__(self, fd=1, output=None, synchronize=True):

def __enter__(self):
if self.std:
# important: flush the current file buffer when redirecting
getattr(sys, self.std).flush()
self.original_file = getattr(sys, self.std)
# important: flush the current file buffer when redirecting
self.original_file.flush()
# Duplicate the original standard file descriptor(file
# descriptor 1 or 2) to a different file descriptor number
self.original_fd = os.dup(self.fd)
Expand All @@ -135,7 +135,7 @@ def __enter__(self):
os.dup2(out_fd, self.fd, inheritable=bool(self.std))

# We no longer need this original file descriptor
if out_fd is not self.target:
if not isinstance(self.target, int):
os.close(out_fd)

if self.std:
Expand Down
Loading