Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleaned up kernel action interface.

* Using POST rather than GET.
* Using simple URLs rather than a query string.
* Using a regexp to match the action.
  • Loading branch information...
commit 9fe1c2c826bc6df76172cb2c3192d4ff679559fa 1 parent 7731a50
@ellisonbg ellisonbg authored
View
11 IPython/frontend/html/notebook/notebook.py
@@ -24,7 +24,7 @@
options.define("port", default=8888, help="run on the given port", type=int)
_kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
-
+_kernel_action_regex = r"(?P<action>restart|interrupt)"
class MainHandler(web.RequestHandler):
def get(self):
@@ -43,14 +43,13 @@ def post(self):
class KernelActionHandler(web.RequestHandler):
- def get(self, kernel_id):
+ def post(self, kernel_id, action):
# TODO: figure out a better way of handling RPC style calls.
- if self.request.arguments.has_key('interrupt'):
+ if action == 'interrupt':
self.application.interrupt_kernel(kernel_id)
- if self.request.arguments.has_key('restart'):
+ if action == 'restart':
new_kernel_id = self.application.restart_kernel(kernel_id)
self.write(json.dumps(new_kernel_id))
- logging.info(repr(self.request.arguments))
class ZMQStreamRouter(object):
@@ -176,7 +175,7 @@ def __init__(self):
handlers = [
(r"/", MainHandler),
(r"/kernels", KernelHandler),
- (r"/kernels/%s/actions" % _kernel_id_regex, KernelActionHandler),
+ (r"/kernels/%s/%s" % (_kernel_id_regex, _kernel_action_regex), KernelActionHandler),
(r"/kernels/%s/iopub" % _kernel_id_regex, ZMQStreamHandler, dict(stream_name='iopub')),
(r"/kernels/%s/shell" % _kernel_id_regex, ZMQStreamHandler, dict(stream_name='shell')),
(r"/notebooks", NotebookRootHandler),
View
8 IPython/frontend/html/notebook/static/js/notebook.js
@@ -764,18 +764,18 @@ Kernel.prototype.execute = function (code) {
Kernel.prototype.interrupt = function () {
- $.get(this.kernel_url + "/actions?interrupt=true");
+ $.post(this.kernel_url + "/interrupt");
};
Kernel.prototype.restart = function () {
- url = this.kernel_url + "/actions?restart=true"
+ url = this.kernel_url + "/restart"
var that = this;
- $.getJSON(url, function (kernel_id) {
+ $.post(url, function (kernel_id) {
console.log("Kernel restarted: " + kernel_id);
that.kernel_id = kernel_id;
that.kernel_url = that.base_url + "/" + that.kernel_id;
- });
+ }, 'json');
};
Please sign in to comment.
Something went wrong with that request. Please try again.