Permalink
Browse files

Added command to shutdown the kernel

  • Loading branch information...
1 parent 4f61859 commit 807c37ae9677f5898897ce7246fa60c5fb5aa92e @paulofilip3 paulofilip3 committed Feb 2, 2014
Showing with 26 additions and 5 deletions.
  1. +3 −2 Default.sublime-commands
  2. +10 −0 ipy_connection.py
  3. +8 −3 ipy_view.py
  4. +5 −0 subl_ipy_notebook.py
View
@@ -1,8 +1,9 @@
[
- { "caption": "Open IPython Notebook", "command": "inb_prompt_list_notebooks" },
- { "caption": "Save IPython Notebook", "command": "inb_save_notebook" },
+ { "caption": "Open IPython Notebook", "command": "inb_prompt_list_notebooks" },
+ { "caption": "Save IPython Notebook", "command": "inb_save_notebook" },
{ "caption": "Restart IPython Notebook Kernel", "command": "inb_restart_kernel" },
{ "caption": "Interrupt IPython Notebook Kernel", "command": "inb_interrupt_kernel" },
+ { "caption": "Shutdown IPython Notebook Kernel", "command": "inb_shutdown_kernel" },
{ "caption": "Open Current Notebook As Ipynb File", "command": "inb_open_as_ipynb" },
{ "caption": "Rename IPython Notebook", "command": "inb_rename_notebook" }
]
View
@@ -286,6 +286,15 @@ def interrupt_kernel(self):
req = urlopen(url, data=bytearray(b""))
req.read()
+ def shutdown_kernel(self):
+ url = self.baseurl + "/kernels/" + self.kernel_id
+ req = Request(url)
+ req.add_header("Content-Type", "application/json")
+ req.get_method = lambda: "DELETE"
+ data = urlopen(req)
+ data.read()
+ self.status_callback("closed")
+
def get_notebook(self):
req = urlopen(self.notebook_url)
try:
@@ -303,6 +312,7 @@ def save_notebook(self, notebook):
request.get_method = lambda: "PUT"
data = urlopen(request)
data.read()
+ self.status_callback("idle")
def on_iopub_msg(self, msg):
m = json.loads(msg)
View
@@ -189,8 +189,8 @@ def is_R_cell(self):
return (len(code) >= 3) and (code[:3] == '%%R')
def check_R(self):
- if self.old_is_R != self.is_R_cell():
- self.update_prompt_number()
+ if self.old_is_R != self.is_R_cell():
+ self.update_prompt_number()
def rewrite_prompt_number(self, edit):
if (self.prompt == self.old_prompt_number) and (self.old_is_R == self.is_R_cell()):
@@ -477,6 +477,11 @@ def restart_kernel(self):
cell.running = False
self.kernel.restart_kernel()
+ def shutdown_kernel(self):
+ for cell in self.cells:
+ if isinstance(cell, CodeCellView):
+ cell.running = False
+ self.kernel.shutdown_kernel()
def on_status(self, execution_state):
def set_status():
@@ -671,6 +676,6 @@ def get_nb_view(self, view):
def on_close(self, view):
id = view.id()
if id in self.views:
- del self.views[id]
+ del self.views[id]
manager = NotebookViewManager()
View
@@ -141,6 +141,11 @@ def run(self, edit):
def description(self):
return "Save IPython notebook"
+class InbShutdownKernelCommand(sublime_plugin.TextCommand):
+ def run(self, edit):
+ nbview = manager.get_nb_view(self.view)
+ if nbview and nbview.kernel:
+ nbview.kernel.shutdown_kernel()
class InbBackspaceCommand(sublime_plugin.TextCommand):
def run(self, edit):

0 comments on commit 807c37a

Please sign in to comment.