Skip to content

Commit c1625b9

Browse files
authored
Merge pull request Pyomo#3560 from jsiirola/tee-test-fixes
Address two intermittent test failures when capturing output
2 parents a70451d + a6568ff commit c1625b9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: pyomo/common/tee.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ def __init__(self, fd=1, output=None, synchronize=True):
120120

121121
def __enter__(self):
122122
if self.std:
123+
# We used to flush original_file here. We have removed that
124+
# because the std* streams are flushed by capture_output.
125+
# Flushing again here caused intermittent errors due to
126+
# closed file handles on OSX
123127
self.original_file = getattr(sys, self.std)
124-
# important: flush the current file buffer when redirecting
125-
self.original_file.flush()
126128
# Duplicate the original standard file descriptor(file
127129
# descriptor 1 or 2) to a different file descriptor number
128130
self.original_fd = os.dup(self.fd)

Diff for: pyomo/common/tests/test_tee.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,18 @@ def test_exit_on_del(self):
589589
remaining_attempts = 4
590590
while len(stack) and remaining_attempts:
591591
gc.collect()
592+
time.sleep(((4 - remaining_attempts) / 4.0) ** 2)
592593
remaining_attempts -= 1
593-
self.assertEqual(len(stack), 0)
594+
try:
595+
self.assertEqual(len(stack), 0)
596+
except:
597+
# We still want to unwind the context managers if the test fails:
598+
while stack:
599+
try:
600+
stack.pop().__exit__(None, None, None)
601+
except:
602+
pass
603+
raise
594604

595605
def test_deadlock(self):
596606
class MockStream(object):

0 commit comments

Comments
 (0)