Skip to content

Commit

Permalink
Fixed broken highs_api.py
Browse files Browse the repository at this point in the history
Fixed unsupportedoperation: fileno exception when launching the solver.
  • Loading branch information
postlogist committed Aug 4, 2023
1 parent abb4bb3 commit 9c424f8
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions pulp/apis/highs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,36 @@ def actualSolve(self, lp):

with open(tmpOptions, "w") as options_file:
options_file.write("\n".join(file_options))
process = subprocess.run(command, stdout=sys.stdout, stderr=sys.stderr)
# test - added by postlogist
if self.msg:
pipe = None
else:
pipe = open(os.devnull, "w")

lp_status = None

# process = subprocess.run(command, stdout=sys.stdout, stderr=sys.stderr, universal_newlines=True)
with subprocess.Popen(
#cmd.split(),
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
) as proc, open(tmpLog, "w") as log_file:
for line in proc.stdout:
if self.msg:
sys.__stdout__.write(line)
log_file.write(line)




# HiGHS return code semantics (see: https://github.com/ERGO-Code/HiGHS/issues/527#issuecomment-946575028)
# - -1: error
# - 0: success
# - 1: warning
if process.returncode == -1:
return_code = proc.wait()
if return_code == -1:
raise PulpSolverError("Error while executing HiGHS")

with open(highs_log_file, "r") as log_file:
Expand Down

0 comments on commit 9c424f8

Please sign in to comment.