##// END OF EJS Templates
Simplify kernel manager code
Thomas Kluyver -
Show More
@@ -0,0 +1,2 b''
1 - :meth:`~.KernelManager.start_kernel` and :meth:`~.KernelManager.format_kernel_cmd`
2 no longer accept a ``executable`` parameter. Use the kernelspec machinery instead.
@@ -9,6 +9,7 b' pjoin = os.path.join'
9 9 from IPython.utils.path import get_ipython_dir
10 10 from IPython.utils.py3compat import PY3
11 11 from IPython.utils.traitlets import HasTraits, List, Unicode, Dict, Any
12 from .launcher import make_ipkernel_cmd
12 13
13 14 if os.name == 'nt':
14 15 programdata = os.environ.get('PROGRAMDATA', None)
@@ -107,9 +108,8 b' class KernelSpecManager(HasTraits):'
107 108 The native kernel is the kernel using the same Python runtime as this
108 109 process. This will put its informatino in the user kernels directory.
109 110 """
110 return {'argv':[sys.executable, '-c',
111 'from IPython.kernel.zmq.kernelapp import main; main()',
112 '-f', '{connection_file}'],
111 return {'argv':make_ipkernel_cmd(
112 'from IPython.kernel.zmq.kernelapp import main; main()'),
113 113 'display_name': 'IPython (Python %d)' % (3 if PY3 else 2),
114 114 'language': 'python',
115 115 'codemirror_mode': {'name': 'ipython',
@@ -97,14 +97,11 b' def make_ipkernel_cmd(code, executable=None, extra_arguments=[], **kw):'
97 97
98 98 A Popen command list
99 99 """
100
101 # Build the kernel launch command.
102 100 if executable is None:
103 101 executable = sys.executable
104 102 arguments = [ executable, '-c', code, '-f', '{connection_file}' ]
105 103 arguments.extend(extra_arguments)
106 104
107 # Spawn a kernel.
108 105 if sys.platform == 'win32':
109 106
110 107 # If the kernel is running on pythonw and stdout/stderr are not been
@@ -159,18 +159,13 b' class KernelManager(ConnectionFileMixin):'
159 159 # Kernel management
160 160 #--------------------------------------------------------------------------
161 161
162 def format_kernel_cmd(self, **kw):
162 def format_kernel_cmd(self, extra_arguments=None):
163 163 """replace templated args (e.g. {connection_file})"""
164 extra_arguments = extra_arguments or []
164 165 if self.kernel_cmd:
165 cmd = self.kernel_cmd
166 elif self.kernel_name == kernelspec.NATIVE_KERNEL_NAME:
167 # The native kernel gets special handling
168 cmd = make_ipkernel_cmd(
169 'from IPython.kernel.zmq.kernelapp import main; main()',
170 **kw
171 )
166 cmd = self.kernel_cmd + extra_arguments
172 167 else:
173 cmd = self.kernel_spec.argv
168 cmd = self.kernel_spec.argv + extra_arguments
174 169
175 170 ns = dict(connection_file=self.connection_file)
176 171 ns.update(self._launch_args)
@@ -227,7 +222,8 b' class KernelManager(ConnectionFileMixin):'
227 222 # save kwargs for use in restart
228 223 self._launch_args = kw.copy()
229 224 # build the Popen cmd
230 kernel_cmd = self.format_kernel_cmd(**kw)
225 extra_arguments = kw.pop('extra_arguments', [])
226 kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments)
231 227 if self.kernel_cmd:
232 228 # If kernel_cmd has been set manually, don't refer to a kernel spec
233 229 env = os.environ
General Comments 0
You need to be logged in to leave comments. Login now