-
Notifications
You must be signed in to change notification settings - Fork 545
Resolve intermittent capture_output
deadlock
#3601
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
97677ea
Rework gurobi to avoid use of default Env
jsiirola a5f2f22
Rework available() implementation / caching for gurobi interfaces
jsiirola fee116c
Fix error message (remove reference to APPSI)
jsiirola f3312c4
Simplify HiGHS output management (avoid nested TeeStreams)
jsiirola 6336c8d
Add lock so entering/leaving capture_output is atomic
jsiirola 6324038
Rework polling to bound polling interval around 1.6 seconds
jsiirola 8fdb7de
gurobi available(): minor rework, add comments
jsiirola 7a51c18
Test using capture_output with a closed stdout
jsiirola 0741b78
Test atomic deadlock
jsiirola 8b5ac8c
Make capture_output more stateless
jsiirola 1d72abd
support calling capture_output.reset() on 'closed' instances
jsiirola ec38f30
TeeStream should close when exiting the outermost context
jsiirola 41b722a
simplify TeeStream flush handling
jsiirola bbaa344
NFC: fix comment
jsiirola 4028582
simplify model construction
jsiirola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,11 @@ | |
|
||
from io import StringIO, BytesIO | ||
|
||
from pyomo.common.errors import DeveloperError | ||
from pyomo.common.log import LoggingIntercept, LogStream | ||
import pyomo.common.unittest as unittest | ||
from pyomo.common.tempfiles import TempfileManager | ||
import pyomo.common.tee as tee | ||
import pyomo.common.unittest as unittest | ||
|
||
|
||
class timestamper: | ||
|
@@ -335,6 +336,17 @@ def test_duplicate_capture_output(self): | |
finally: | ||
capture.reset() | ||
|
||
def test_reset_capture_output_twice(self): | ||
capture = tee.capture_output() | ||
with capture as OUT1: | ||
print("test1") | ||
capture.reset() | ||
capture.reset() | ||
with capture as OUT2: | ||
print("test2") | ||
self.assertEqual(OUT1.getvalue(), "test1\n") | ||
self.assertEqual(OUT2.getvalue(), "test2\n") | ||
|
||
def test_capture_output_logfile_string(self): | ||
with TempfileManager.new_context() as tempfile: | ||
logfile = tempfile.create_tempfile() | ||
|
@@ -537,6 +549,14 @@ def test_no_fileno_stdout(self): | |
with T: | ||
self.assertEqual(len(T.context_stack), 6) | ||
|
||
def test_closed_stdout(self): | ||
with tee.capture_output() as T_outer: | ||
sys.stdout.close() | ||
with tee.capture_output() as T_inner: | ||
print("test") | ||
self.assertEqual(T_outer.getvalue(), "") | ||
self.assertEqual(T_inner.getvalue(), "test\n") | ||
|
||
def test_capture_output_stack_error(self): | ||
OUT1 = StringIO() | ||
OUT2 = StringIO() | ||
|
@@ -559,6 +579,31 @@ def test_capture_output_stack_error(self): | |
sys.stdout, sys.stderr = old | ||
logging.getLogger('pyomo.common.tee').handlers.clear() | ||
|
||
def test_atomic_deadlock(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nifty test, I like it. |
||
save_poll = tee._poll_timeout_deadlock | ||
tee._poll_timeout_deadlock = 0.01 | ||
|
||
co = tee.capture_output() | ||
try: | ||
tee.capture_output.startup_shutdown.acquire() | ||
with self.assertRaisesRegex( | ||
DeveloperError, "Deadlock starting capture_output" | ||
): | ||
with tee.capture_output(): | ||
pass | ||
tee.capture_output.startup_shutdown.release() | ||
|
||
with self.assertRaisesRegex( | ||
DeveloperError, "Deadlock closing capture_output" | ||
): | ||
with co: | ||
tee.capture_output.startup_shutdown.acquire() | ||
finally: | ||
tee._poll_timeout_deadlock = save_poll | ||
if tee.capture_output.startup_shutdown.locked(): | ||
tee.capture_output.startup_shutdown.release() | ||
co.reset() | ||
|
||
def test_capture_output_invalid_ostream(self): | ||
# Test that capture_output does not suppress errors from the tee | ||
# module | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.