From 169dad328f759eccab2bce8d1f882ba5694784a3 Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Vargas Date: Thu, 22 Sep 2022 18:50:58 -0500 Subject: [PATCH] Use message instead of interrupt for Windows --- src/Malt.jl | 9 ++++++++- src/worker.jl | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Malt.jl b/src/Malt.jl index a4d411a..9e46fcf 100644 --- a/src/Malt.jl +++ b/src/Malt.jl @@ -271,6 +271,13 @@ kill(w::Worker) = Base.kill(w.proc) Send an interrupt signal to the worker process. This will interrupt the latest request (`remotecall*` or `remote_eval*`) that was sent to the worker. """ -interrupt(w::Worker) = Base.kill(w.proc, Base.SIGINT) +function interrupt(w::Worker) + if Sys.iswindows() + isrunning(w) || throw(TerminatedWorkerException()) + _send_msg(w.port, (header=:interrupt,)) + else + Base.kill(w.proc, Base.SIGINT) + end +end end # module diff --git a/src/worker.jl b/src/worker.jl index cd4e6b7..aaa8c5b 100644 --- a/src/worker.jl +++ b/src/worker.jl @@ -34,8 +34,14 @@ function serve(server::Sockets.TCPServer) # Handle request asynchronously latest = @async begin msg = deserialize(sock) - @debug(msg) - handle(Val(msg.header), sock, msg) + if get(msg, :header, nothing) === :interrupt + if latest isa Task && !istaskdone(latest) + Base.throwto(latest, InterruptException) + end + else + @debug(msg) + handle(Val(msg.header), sock, msg) + end end catch InterruptException # Rethrow interrupt in the latest task