Show More
@@ -23,9 +23,10 b' import zmq' | |||||
23 |
|
23 | |||
24 | # Local imports |
|
24 | # Local imports | |
25 | from IPython.config.configurable import LoggingConfigurable |
|
25 | from IPython.config.configurable import LoggingConfigurable | |
|
26 | from IPython.utils.importstring import import_item | |||
26 | from IPython.utils.localinterfaces import LOCAL_IPS |
|
27 | from IPython.utils.localinterfaces import LOCAL_IPS | |
27 | from IPython.utils.traitlets import ( |
|
28 | from IPython.utils.traitlets import ( | |
28 | Any, Instance, Unicode, List, Bool, |
|
29 | Any, Instance, Unicode, List, Bool, Type, DottedObjectName | |
29 | ) |
|
30 | ) | |
30 | from IPython.kernel import ( |
|
31 | from IPython.kernel import ( | |
31 | make_ipkernel_cmd, |
|
32 | make_ipkernel_cmd, | |
@@ -65,6 +66,12 b' class KernelManager(LoggingConfigurable, ConnectionFileMixin):' | |||||
65 | def _session_default(self): |
|
66 | def _session_default(self): | |
66 | return Session(config=self.config) |
|
67 | return Session(config=self.config) | |
67 |
|
68 | |||
|
69 | # the class to create with our `client` method | |||
|
70 | client_class = DottedObjectName('IPython.kernel.client.KernelClient') | |||
|
71 | client_factory = Type() | |||
|
72 | def _client_class_changed(self, name, old, new): | |||
|
73 | self.client_factory = import_item(str(new)) | |||
|
74 | ||||
68 | # The kernel process with which the KernelManager is communicating. |
|
75 | # The kernel process with which the KernelManager is communicating. | |
69 | # generally a Popen instance |
|
76 | # generally a Popen instance | |
70 | kernel = Any() |
|
77 | kernel = Any() | |
@@ -103,6 +110,23 b' class KernelManager(LoggingConfigurable, ConnectionFileMixin):' | |||||
103 | pass |
|
110 | pass | |
104 |
|
111 | |||
105 | #-------------------------------------------------------------------------- |
|
112 | #-------------------------------------------------------------------------- | |
|
113 | # create a Client connected to our Kernel | |||
|
114 | #-------------------------------------------------------------------------- | |||
|
115 | ||||
|
116 | def client(self, **kwargs): | |||
|
117 | """Create a client configured to connect to our kernel""" | |||
|
118 | if self.client_factory is None: | |||
|
119 | self.client_factory = import_item(self.client_class) | |||
|
120 | ||||
|
121 | kw = {} | |||
|
122 | kw.update(self.get_connection_info()) | |||
|
123 | kw['connection_file'] = self.connection_file | |||
|
124 | ||||
|
125 | # add kwargs last, for manual overrides | |||
|
126 | kw.update(kwargs) | |||
|
127 | return self.client_factory(**kw) | |||
|
128 | ||||
|
129 | #-------------------------------------------------------------------------- | |||
106 | # Connection info |
|
130 | # Connection info | |
107 | #-------------------------------------------------------------------------- |
|
131 | #-------------------------------------------------------------------------- | |
108 |
|
132 | |||
@@ -174,18 +198,19 b' class KernelManager(LoggingConfigurable, ConnectionFileMixin):' | |||||
174 | """ |
|
198 | """ | |
175 | return launch_kernel(kernel_cmd, **kw) |
|
199 | return launch_kernel(kernel_cmd, **kw) | |
176 |
|
200 | |||
|
201 | # Control socket used for polite kernel shutdown | |||
|
202 | ||||
177 | def _connect_control_socket(self): |
|
203 | def _connect_control_socket(self): | |
178 | if self._control_socket is None: |
|
204 | if self._control_socket is None: | |
179 | self._control_socket = self.connect_control() |
|
205 | self._control_socket = self.connect_control() | |
|
206 | self._control_socket.linger = 100 | |||
180 |
|
207 | |||
181 | def _close_control_socket(self): |
|
208 | def _close_control_socket(self): | |
182 | if self._control_socket is None: |
|
209 | if self._control_socket is None: | |
183 | return |
|
210 | return | |
184 | self._control_socket.linger = 100 |
|
|||
185 | self._control_socket.close() |
|
211 | self._control_socket.close() | |
186 | self._control_socket = None |
|
212 | self._control_socket = None | |
187 |
|
213 | |||
188 |
|
||||
189 | def start_kernel(self, **kw): |
|
214 | def start_kernel(self, **kw): | |
190 | """Starts a kernel on this host in a separate process. |
|
215 | """Starts a kernel on this host in a separate process. | |
191 |
|
216 |
@@ -31,14 +31,14 b' from IPython.utils.traitlets import (' | |||||
31 | def setup(): |
|
31 | def setup(): | |
32 | global KM, KC |
|
32 | global KM, KC | |
33 | KM = KernelManager() |
|
33 | KM = KernelManager() | |
|
34 | KM.client_factory = BlockingKernelClient | |||
34 | KM.start_kernel(stdout=PIPE, stderr=PIPE) |
|
35 | KM.start_kernel(stdout=PIPE, stderr=PIPE) | |
35 | KC = BlockingKernelClient(connection_file=KM.connection_file) |
|
36 | KC = KM.client() | |
36 | KC.load_connection_file() |
|
|||
37 | KC.start_channels() |
|
37 | KC.start_channels() | |
38 |
|
38 | |||
39 | # wait for kernel to be ready |
|
39 | # wait for kernel to be ready | |
40 |
KC |
|
40 | KC.execute("pass") | |
41 |
KC. |
|
41 | KC.get_shell_msg(block=True, timeout=5) | |
42 | flush_channels() |
|
42 | flush_channels() | |
43 |
|
43 | |||
44 |
|
44 |
General Comments 0
You need to be logged in to leave comments.
Login now