Skip to content

Commit

Permalink
Use disable_sigint to allow interrupts only between iterations (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 14, 2024
1 parent 3b2570b commit 2fd1e8d
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/plugins/parallel_schemes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,23 @@ function master_loop(
options::Options,
) where {T}
_initialize_solver(model; throw_error = false)
while true
result = iteration(model, options)
options.post_iteration_callback(result)
log_iteration(options)
if result.has_converged
return result.status
status = nothing
while status === nothing
# Disable CTRL+C so that InterruptExceptions can be thrown only between
# each iteration. Note that if the user presses CTRL+C during an
# iteration, then this will be cached and re-thrown as disable_sigint
# exits.
status = disable_sigint() do
result = iteration(model, options)
options.post_iteration_callback(result)
log_iteration(options)
if result.has_converged
return result.status
end
return nothing
end
end
return
return status
end

function _simulate(
Expand Down Expand Up @@ -367,13 +375,20 @@ function master_loop(
# doesn't matter because all it will do is another iteration
# before terminating.
while keep_iterating
result = iteration(model, options)
lock(options.lock) do
options.post_iteration_callback(result)
log_iteration(options)
if result.has_converged
keep_iterating = false
status = result.status
# Disable CTRL+C so that InterruptExceptions can be thrown
# only between each iteration. Note that if the user presses
# CTRL+C during an iteration, then this will be cached and
# re-thrown as disable_sigint exits.
disable_sigint() do
result = iteration(model, options)
lock(options.lock) do
options.post_iteration_callback(result)
log_iteration(options)
if result.has_converged
keep_iterating = false
status = result.status
end
return
end
return
end
Expand Down

0 comments on commit 2fd1e8d

Please sign in to comment.