Skip to content

Commit 6b8ac9d

Browse files
committed
capture output when setting parameter, as suggested by @jsiirola
1 parent e510a7d commit 6b8ac9d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pyomo/solvers/plugins/solvers/gurobi_direct.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,13 @@ def available(self, exception_flag=True):
239239
def _apply_solver(self):
240240
StaleFlagManager.mark_all_as_stale()
241241

242-
if self._tee:
243-
self._solver_model.setParam('LogToConsole', 1)
244-
else:
245-
self._solver_model.setParam('LogToConsole', 0)
242+
# We would like to just set OutputFlag to turn off the console
243+
# log, but that prevents users from using the Gurobi LogFile
244+
# option (see #3589 / #3716). BUT just setting LogToConsole
245+
# triggers Gurobi to write a message to the console. We will
246+
# capture that message here:
247+
with capture_output(capture_fd=True):
248+
self._solver_model.setParam('LogToConsole', int(bool(self._tee)))
246249

247250
if self._keepfiles:
248251
# Only save log file when the user wants to keep it.

0 commit comments

Comments
 (0)