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