##// END OF EJS Templates
Start refactoring KernelManager to use kernel registry
Thomas Kluyver -
Show More
@@ -100,6 +100,8 b' def get_kernel_spec(kernel_name):'
100 100
101 101 Raises KeyError if the given kernel name is not found.
102 102 """
103 if kernel_name == 'native':
104 kernel_name = NATIVE_KERNEL_NAME
103 105 d = list_kernel_specs()
104 106 resource_dir = d[kernel_name.lower()]
105 107 return KernelSpec.from_resource_dir(resource_dir) No newline at end of file
@@ -18,6 +18,7 b' import re'
18 18 import signal
19 19 import sys
20 20 import time
21 import warnings
21 22
22 23 import zmq
23 24
@@ -31,6 +32,7 b' from IPython.utils.traitlets import ('
31 32 from IPython.kernel import (
32 33 make_ipkernel_cmd,
33 34 launch_kernel,
35 kernelspec,
34 36 )
35 37 from .connect import ConnectionFileMixin
36 38 from .zmq.session import Session
@@ -68,8 +70,21 b' class KernelManager(LoggingConfigurable, ConnectionFileMixin):'
68 70 # generally a Popen instance
69 71 kernel = Any()
70 72
73 kernel_name = Unicode('native')
74
75 kernel_spec = Instance(kernelspec.KernelSpec)
76
77 def _kernel_spec_default(self):
78 return kernelspec.get_kernel_spec(self.kernel_name)
79
80 def _kernel_name_changed(self, name, old, new):
81 self.kernel_spec = kernelspec.get_kernel_spec(new)
82 self.ipython_kernel = new in {'native', 'python2', 'python3'}
83
71 84 kernel_cmd = List(Unicode, config=True,
72 help="""The Popen Command to launch the kernel.
85 help="""DEPRECATED: Use kernel_name instead.
86
87 The Popen Command to launch the kernel.
73 88 Override this if you have a custom kernel.
74 89 If kernel_cmd is specified in a configuration file,
75 90 IPython does not pass any arguments to the kernel,
@@ -81,6 +96,8 b' class KernelManager(LoggingConfigurable, ConnectionFileMixin):'
81 96 )
82 97
83 98 def _kernel_cmd_changed(self, name, old, new):
99 warnings.warn("Setting kernel_cmd is deprecated, use kernel_spec to "
100 "start different kernels.")
84 101 self.ipython_kernel = False
85 102
86 103 ipython_kernel = Bool(True)
@@ -150,11 +167,15 b' class KernelManager(LoggingConfigurable, ConnectionFileMixin):'
150 167 """replace templated args (e.g. {connection_file})"""
151 168 if self.kernel_cmd:
152 169 cmd = self.kernel_cmd
153 else:
170 elif self.kernel_name == 'native':
171 # The native kernel gets special handling
154 172 cmd = make_ipkernel_cmd(
155 173 'from IPython.kernel.zmq.kernelapp import main; main()',
156 174 **kw
157 175 )
176 else:
177 cmd = self.kernel_spec.argv
178
158 179 ns = dict(connection_file=self.connection_file)
159 180 ns.update(self._launch_args)
160 181
General Comments 0
You need to be logged in to leave comments. Login now