File tree Expand file tree Collapse file tree 2 files changed +24
-13
lines changed Expand file tree Collapse file tree 2 files changed +24
-13
lines changed Original file line number Diff line number Diff line change @@ -629,29 +629,31 @@ function optimize_multiobjective!(
629629 return minimize_multiobjective! (algorithm, model)
630630end
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
655657end
656658
657659function MOI. optimize! (model:: Optimizer )
Original file line number Diff line number Diff line change @@ -225,6 +225,15 @@ function test_SubproblemCount()
225225 return
226226end
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+
228237end # module
229238
230239TestModel. run_tests ()
You can’t perform that action at this time.
0 commit comments