Skip to content

Commit

Permalink
Implement message interrupt mode (#804)
Browse files Browse the repository at this point in the history
Default to message mode for Windows and keep the previous behaviour for
all other platforms.
  • Loading branch information
filmor authored and stevengj committed Feb 11, 2019
1 parent 8e7f10f commit 604c9a7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions deps/kspec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ function installkernel(name::AbstractString, julia_options::AbstractString...;
"display_name" => name * " " * Base.VERSION_STRING * debugdesc,
"language" => "julia",
"env" => env,
# Jupyter's signal interrupt mode is not supported on Windows
"interrupt_mode" => Sys.iswindows() ? "message" : "signal",
)

mkpath(juliakspec)
Expand Down
5 changes: 3 additions & 2 deletions src/eventloop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ function eventloop(socket)
end
end

const requests_task = Ref{Task}()
function waitloop()
@async eventloop(control[])
requests_task = @async eventloop(requests[])
requests_task[] = @async eventloop(requests[])
while true
try
wait()
catch e
# send interrupts (user SIGINT) to the code-execution task
if isa(e, InterruptException)
@async Base.throwto(requests_task, e)
@async Base.throwto(requests_task[], e)
else
rethrow()
end
Expand Down
6 changes: 6 additions & 0 deletions src/handlers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ function is_complete_request(socket, msg)
Dict("status"=>status, "indent"=>"")))
end

function interrupt_request(socket, msg)
@async Base.throwto(requests_task[], InterruptException())
send_ipython(requests[], msg_reply(msg, "interrupt_reply", Dict()))
end

const handlers = Dict{String,Function}(
"execute_request" => execute_request,
"complete_request" => complete_request,
Expand All @@ -270,6 +275,7 @@ const handlers = Dict{String,Function}(
"shutdown_request" => shutdown_request,
"history_request" => history_request,
"is_complete_request" => is_complete_request,
"interrupt_request" => interrupt_request,
"comm_open" => comm_open,
"comm_info_request" => comm_info_request,
"comm_msg" => comm_msg,
Expand Down
2 changes: 1 addition & 1 deletion src/msg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ msg_header(m::Msg, msg_type::String) = Dict("msg_id" => uuid4(),
"session" => m.header["session"],
"date" => now(),
"msg_type" => msg_type,
"version" => "5.0")
"version" => "5.3")

# PUB/broadcast messages use the msg_type as the ident, except for
# stream messages which use the stream name (e.g. "stdout").
Expand Down

0 comments on commit 604c9a7

Please sign in to comment.