Skip to content

Commit 0d4bfcd

Browse files
authored
Fix flush of stdout after solve (#275)
1 parent ae9186d commit 0d4bfcd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/c_wrapper.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,5 +402,9 @@ function _unsafe_scs_solve(model::_ScsDataWrapper{S,T}) where {S,T}
402402
model.options[:warm_start],
403403
)
404404
scs_finish(model.linear_solver, scs_work)
405+
# SCS does not flush stdout on exit, and the C stdout is not the same as
406+
# Julia's stdout, so regular calls to flush(stdout) do not work. A
407+
# work-around is for us to manually flush the output after each solve.
408+
Base.Libc.flush_cstdio()
405409
return Solution(model.primal, model.dual, model.slack, scs_info, status)
406410
end

test/MOI_wrapper.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,26 @@ function test_Name_skip()
181181
return
182182
end
183183

184+
function test_redirect_stdout()
185+
filename = tempname()
186+
open(filename, "w") do io
187+
redirect_stdout(io) do
188+
model = MOI.Utilities.Model{Float64}()
189+
x = MOI.add_variables(model, 3)
190+
f = MOI.Utilities.operate(vcat, Float64, 1.0 .* x...)
191+
MOI.add_constraint(model, f, MOI.Nonnegatives(3))
192+
scs = SCS.Optimizer()
193+
MOI.optimize!(scs, model)
194+
return
195+
end
196+
return
197+
end
198+
output = read(filename, String)
199+
@test occursin("SCS", output)
200+
@test length(output) > 100
201+
return
202+
end
203+
184204
end # module
185205

186206
TestSCS.runtests()

0 commit comments

Comments
 (0)