When using the Gurobi Python package (gurobipy v. 8.1.0) alongside the standard Python logging package, I get on console a doubled output for Gurobi, for example
Total elapsed time = 498.27s
[2019-03-04 17:51:58,804][INFO] Total elapsed time = 498.27s
Does anybody know how to remove logging for gurobipy? Thanks
I had this problem as well. Couldn't find an "official" solution so I rolled my own hack:
import sys
def solve():
class DevNull:
def write(self, *args, **kwargs):
pass
def flush(self, *args, **kwargs):
pass
sys.stdout = DevNull()
try:
return _actually_solve()
except Exception:
# restore stdout so that handlers can print normally
# https://docs.python.org/3/library/sys.html#sys.__stdout__
sys.stdout = sys.__stdout__
raise
finally:
sys.stdout = sys.__stdout__
This function wraps the actual solving logic in _actually_solve
and replaces the standard output with a file-like object that ignores everything we write there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With