Skip to content

Commit

Permalink
Implement message interrupt mode
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 committed Feb 1, 2019
1 parent 1d7dc50 commit 3f67e40
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions deps/kspec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function installkernel(name::AbstractString, julia_options::AbstractString...;
"display_name" => name * " " * Base.VERSION_STRING * debugdesc,
"language" => "julia",
"env" => env,
"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 3f67e40

Please sign in to comment.