##// END OF EJS Templates
add error catching to kernel manager...
Zachary Sailer -
Show More
@@ -23,7 +23,7 b' from zmq.utils import jsonapi'
23
23
24 from IPython.utils.jsonutil import date_default
24 from IPython.utils.jsonutil import date_default
25
25
26 from ...base.handlers import IPythonHandler
26 from ...base.handlers import IPythonHandler, json_errors
27 from ...base.zmqhandlers import AuthenticatedZMQStreamHandler
27 from ...base.zmqhandlers import AuthenticatedZMQStreamHandler
28
28
29 #-----------------------------------------------------------------------------
29 #-----------------------------------------------------------------------------
@@ -34,11 +34,13 b' from ...base.zmqhandlers import AuthenticatedZMQStreamHandler'
34 class MainKernelHandler(IPythonHandler):
34 class MainKernelHandler(IPythonHandler):
35
35
36 @web.authenticated
36 @web.authenticated
37 @json_errors
37 def get(self):
38 def get(self):
38 km = self.kernel_manager
39 km = self.kernel_manager
39 self.finish(jsonapi.dumps(km.list_kernels()))
40 self.finish(jsonapi.dumps(km.list_kernels(self.ws_url)))
40
41
41 @web.authenticated
42 @web.authenticated
43 @json_errors
42 def post(self):
44 def post(self):
43 km = self.kernel_manager
45 km = self.kernel_manager
44 kernel_id = km.start_kernel()
46 kernel_id = km.start_kernel()
@@ -52,12 +54,14 b' class KernelHandler(IPythonHandler):'
52 SUPPORTED_METHODS = ('DELETE', 'GET')
54 SUPPORTED_METHODS = ('DELETE', 'GET')
53
55
54 @web.authenticated
56 @web.authenticated
57 @json_errors
55 def get(self, kernel_id):
58 def get(self, kernel_id):
56 km = self.kernel_manager
59 km = self.kernel_manager
57 model = km.kernel_model(kernel_id, self.ws_url)
60 model = km.kernel_model(kernel_id, self.ws_url)
58 self.finish(jsonapi.dumps(model))
61 self.finish(jsonapi.dumps(model))
59
62
60 @web.authenticated
63 @web.authenticated
64 @json_errors
61 def delete(self, kernel_id):
65 def delete(self, kernel_id):
62 km = self.kernel_manager
66 km = self.kernel_manager
63 km.shutdown_kernel(kernel_id)
67 km.shutdown_kernel(kernel_id)
@@ -68,6 +72,7 b' class KernelHandler(IPythonHandler):'
68 class KernelActionHandler(IPythonHandler):
72 class KernelActionHandler(IPythonHandler):
69
73
70 @web.authenticated
74 @web.authenticated
75 @json_errors
71 def post(self, kernel_id, action):
76 def post(self, kernel_id, action):
72 km = self.kernel_manager
77 km = self.kernel_manager
73 if action == 'interrupt':
78 if action == 'interrupt':
@@ -79,9 +79,14 b' class MappingKernelManager(MultiKernelManager):'
79 model = {"id":kernel_id, "ws_url": ws_url}
79 model = {"id":kernel_id, "ws_url": ws_url}
80 return model
80 return model
81
81
82 def list_kernels(self):
82 def list_kernels(self, ws_url):
83 """Returns a list of kernel_id's of kernels running."""
83 """Returns a list of kernel_id's of kernels running."""
84 return super(MappingKernelManager, self).list_kernel_ids()
84 kernels = []
85 kernel_ids = super(MappingKernelManager, self).list_kernel_ids()
86 for kernel_id in kernel_ids:
87 model = self.kernel_model(kernel_id, ws_url)
88 kernels.append(model)
89 return kernels
85
90
86 # override _check_kernel_id to raise 404 instead of KeyError
91 # override _check_kernel_id to raise 404 instead of KeyError
87 def _check_kernel_id(self, kernel_id):
92 def _check_kernel_id(self, kernel_id):
@@ -36,7 +36,7 b' class KernelAPITest(NotebookTestBase):'
36 # GET request
36 # GET request
37 r = requests.get(self.base_url())
37 r = requests.get(self.base_url())
38 assert isinstance(r.json(), list)
38 assert isinstance(r.json(), list)
39 self.assertEqual(r.json()[0], data['id'])
39 self.assertEqual(r.json()[0]['id'], data['id'])
40
40
41 def test_kernel_handler(self):
41 def test_kernel_handler(self):
42 # GET kernel with id
42 # GET kernel with id
@@ -228,8 +228,8 b' class FileNotebookManager(NotebookManager):'
228 self.log.debug("Unlinking checkpoint %s", cp_path)
228 self.log.debug("Unlinking checkpoint %s", cp_path)
229 os.unlink(cp_path)
229 os.unlink(cp_path)
230
230
231 self.log.debug("Unlinking notebook %s", nb_path)
231 self.log.debug("Unlinking notebook %s", os_path)
232 os.unlink(nb_path)
232 os.unlink(os_path)
233
233
234 def rename_notebook(self, old_name, old_path, new_name, new_path):
234 def rename_notebook(self, old_name, old_path, new_name, new_path):
235 """Rename a notebook."""
235 """Rename a notebook."""
General Comments 0
You need to be logged in to leave comments. Login now