Skip to content

Commit 7b3670f

Browse files
committed
Merge pull request #21 from paulofilip3/master
Shutdown Kernel
2 parents 99190f0 + 123e64a commit 7b3670f

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.pyc
22
*.bak
33
*.cache
4-
.DS_Store
4+
.DS_Store
5+
.idea

Diff for: Default.sublime-commands

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[
2-
{ "caption": "Open IPython Notebook", "command": "inb_prompt_list_notebooks" },
3-
{ "caption": "Save IPython Notebook", "command": "inb_save_notebook" },
2+
{ "caption": "Open IPython Notebook", "command": "inb_prompt_list_notebooks" },
3+
{ "caption": "Save IPython Notebook", "command": "inb_save_notebook" },
44
{ "caption": "Restart IPython Notebook Kernel", "command": "inb_restart_kernel" },
55
{ "caption": "Interrupt IPython Notebook Kernel", "command": "inb_interrupt_kernel" },
6+
{ "caption": "Shutdown IPython Notebook Kernel", "command": "inb_shutdown_kernel" },
67
{ "caption": "Open Current Notebook As Ipynb File", "command": "inb_open_as_ipynb" },
78
{ "caption": "Rename IPython Notebook", "command": "inb_rename_notebook" }
89
]

Diff for: ipy_connection.py

+9
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ def interrupt_kernel(self):
286286
req = urlopen(url, data=bytearray(b""))
287287
req.read()
288288

289+
def shutdown_kernel(self):
290+
url = self.baseurl + "/kernels/" + self.kernel_id
291+
req = Request(url)
292+
req.add_header("Content-Type", "application/json")
293+
req.get_method = lambda: "DELETE"
294+
data = urlopen(req)
295+
data.read()
296+
self.status_callback("closed")
297+
289298
def get_notebook(self):
290299
req = urlopen(self.notebook_url)
291300
try:

Diff for: ipy_view.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ def is_R_cell(self):
189189
return (len(code) >= 3) and (code[:3] == '%%R')
190190

191191
def check_R(self):
192-
if self.old_is_R != self.is_R_cell():
193-
self.update_prompt_number()
192+
if self.old_is_R != self.is_R_cell():
193+
self.update_prompt_number()
194194

195195
def rewrite_prompt_number(self, edit):
196196
if (self.prompt == self.old_prompt_number) and (self.old_is_R == self.is_R_cell()):
@@ -477,6 +477,11 @@ def restart_kernel(self):
477477
cell.running = False
478478
self.kernel.restart_kernel()
479479

480+
def shutdown_kernel(self):
481+
for cell in self.cells:
482+
if isinstance(cell, CodeCellView):
483+
cell.running = False
484+
self.kernel.shutdown_kernel()
480485

481486
def on_status(self, execution_state):
482487
def set_status():
@@ -671,6 +676,6 @@ def get_nb_view(self, view):
671676
def on_close(self, view):
672677
id = view.id()
673678
if id in self.views:
674-
del self.views[id]
679+
del self.views[id]
675680

676681
manager = NotebookViewManager()

Diff for: subl_ipy_notebook.py

+5
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ def run(self, edit):
141141
def description(self):
142142
return "Save IPython notebook"
143143

144+
class InbShutdownKernelCommand(sublime_plugin.TextCommand):
145+
def run(self, edit):
146+
nbview = manager.get_nb_view(self.view)
147+
if nbview and nbview.kernel:
148+
nbview.kernel.shutdown_kernel()
144149

145150
class InbBackspaceCommand(sublime_plugin.TextCommand):
146151
def run(self, edit):

0 commit comments

Comments
 (0)