Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows specific bugs #11

Merged
merged 2 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Malt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ function _recv(socket)
response.result
catch e
rethrow(e)
finally
close(socket)
end
end

Expand Down Expand Up @@ -225,7 +223,6 @@ function worker_channel(w::Worker, expr)::Channel
while isopen(channel) && isopen(s)
put!(channel, deserialize(s))
end
close(s)
return
end)
end
Expand Down Expand Up @@ -274,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
18 changes: 11 additions & 7 deletions src/worker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,16 +64,14 @@ function handle(::Val{:call}, socket, msg)
catch e
# @debug("Exception!", e)
serialize(socket, (status=:err, result=e))
finally
close(socket)
end
end

function handle(::Val{:remote_do}, socket, msg)
try
msg.f(msg.args...; msg.kwargs...)
finally
close(socket)
catch e
nothing
end
end

Expand All @@ -76,7 +80,7 @@ function handle(::Val{:channel}, socket, msg)
while isopen(channel) && isopen(socket)
serialize(socket, take!(channel))
end
isopen(socket) && close(socket)

isopen(channel) && close(channel)
return
end
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using Test

# Terminating workers takes about 0.5s
m.stop(w)
sleep(1)
sleep(2)
@test m.isrunning(w) === false
end

Expand Down Expand Up @@ -74,7 +74,7 @@ end
@test m.isrunning(w) === true

m.stop(w)
sleep(1)
sleep(2)
@test m.isrunning(w) === false
end

Expand Down