Skip to content

Commit 64bcf62

Browse files
committed
Update
1 parent c9be8b0 commit 64bcf62

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/MultiObjectiveAlgorithms.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -629,29 +629,31 @@ function optimize_multiobjective!(
629629
return minimize_multiobjective!(algorithm, model)
630630
end
631631

632-
function _check_premature_termination(model::Optimizer, start_time::Float64)
632+
function _check_interrupt(f)
633633
try
634-
return reenable_sigint() do
635-
time_limit = MOI.get(model, MOI.TimeLimitSec())
636-
if time_limit === nothing
637-
return
638-
end
634+
return reenable_sigint(f)
635+
catch ex
636+
if !(ex isa InterruptException)
637+
rethrow(ex)
638+
end
639+
return MOI.INTERRUPTED
640+
end
641+
end
642+
643+
function _check_premature_termination(model::Optimizer, start_time::Float64)
644+
return _check_interrupt() do
645+
time_limit = MOI.get(model, MOI.TimeLimitSec())
646+
if time_limit !== nothing
639647
time_remaining = time_limit - (time() - start_time)
640648
if time_remaining <= 0
641649
return MOI.TIME_LIMIT
642650
end
643651
if MOI.supports(model.inner, MOI.TimeLimitSec())
644652
MOI.set(model.inner, MOI.TimeLimitSec(), time_remaining)
645653
end
646-
return
647654
end
648-
catch ex
649-
if ex isa InterruptException
650-
return MOI.INTERRUPTED
651-
end
652-
rethrow(ex)
655+
return
653656
end
654-
return nothing # no termination
655657
end
656658

657659
function MOI.optimize!(model::Optimizer)

test/test_model.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ function test_SubproblemCount()
225225
return
226226
end
227227

228+
function test_check_interrupt()
229+
function _test_check_interrupt(err)
230+
return disable_sigint(() -> MOA._check_interrupt(() -> throw(err)))
231+
end
232+
@test _test_check_interrupt(InterruptException()) == MOI.INTERRUPTED
233+
@test_throws ArgumentError("") _test_check_interrupt(ArgumentError(""))
234+
return
235+
end
236+
228237
end # module
229238

230239
TestModel.run_tests()

0 commit comments

Comments
 (0)