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
Abort queued messages if an error occurs #264
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ Executor <- setRefClass( | |
'Executor', | ||
fields = list( | ||
send_response = 'function', | ||
abort_queued_messages = 'function', | ||
execution_count = 'integer', | ||
payload = 'list', | ||
err = 'list', | ||
|
@@ -258,7 +259,13 @@ execute = function(request) { | |
} | ||
|
||
send_response('execute_reply', request, 'shell', reply_content) | ||
|
||
|
||
if (interrupted || !is.null(err$ename)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! |
||
# errors or interrupts should interrupt all currently queued messages, | ||
# not only the currently running one... | ||
abort_queued_messages() | ||
} | ||
|
||
if (!silent) { | ||
execution_count <<- execution_count + 1L | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ new_reply = function(msg_type, parent_msg) { | |
|
||
header <- list( | ||
msg_id = UUIDgenerate(), | ||
username = parent_msg$header$username, | ||
username = parent_msg$header$username, | ||
session = parent_msg$header$session, | ||
msg_type = msg_type, | ||
version = '5.0') | ||
|
@@ -129,6 +129,35 @@ handle_shell = function() { | |
print(c('Got unhandled msg_type:', msg$header$msg_type))) | ||
}, | ||
|
||
abort_shell_msg = function(){ | ||
"Send an abort message for an incoming shell request" | ||
# See https://github.com/ipython/ipykernel/blob/1d97cb2a04149387a0d2dbea1b3d0af691d8df6c/ipykernel/kernelbase.py#L623 | ||
|
||
parts <- zmq.recv.multipart(sockets$shell, unserialize = FALSE) | ||
msg <- wire_to_msg(parts) | ||
reply_type <- paste(strsplit(msg$header$msg_type, "_")[1], "_reply") | ||
reply_content <- list(status = 'aborted') | ||
send_response(reply_type, msg, "shell", reply_content) | ||
}, | ||
|
||
abort_queued_messages = function(){ | ||
"Abort all already queued shell messages after an error" | ||
|
||
while (TRUE) { | ||
ret = zmq.poll( | ||
c(sockets$shell), # only shell channel | ||
c(.pbd_env$ZMQ.PO$POLLIN), # type | ||
0) # zero timeout, only what's already there | ||
|
||
if(bitwAnd(zmq.poll.get.revents(1), .pbd_env$ZMQ.PO$POLLIN)) { | ||
abort_shell_msg() | ||
} else { | ||
# no more messages... | ||
break | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... The above break could probably also go to this if as an |
||
} | ||
}, | ||
|
||
is_complete = function(request) { | ||
"Checks whether the code in the rest is complete" | ||
|
||
|
@@ -264,8 +293,9 @@ initialize = function(connection_file) { | |
zmq.bind(sockets$control, url_with_port('control_port')) | ||
zmq.bind(sockets$stdin, url_with_port('stdin_port')) | ||
zmq.bind(sockets$shell, url_with_port('shell_port')) | ||
|
||
executor <<- Executor$new(send_response = .self$send_response) | ||
|
||
executor <<- Executor$new(send_response = .self$send_response, | ||
abort_queued_messages = .self$abort_queued_messages) | ||
}, | ||
|
||
run = function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R is weird... You have to pass in the function to make them available in a object? Took a while to find this place...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reference classes are weird. they’re “OO like it works in java, added as an afterhought”
please make the
=
signs line up. maybe shorten the name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I formatted it, but I value proper names more than short lines...