##// END OF EJS Templates
Docstring cleanup for kernelmanagers and channels....
Brian Granger -
Show More
@@ -26,8 +26,7 b' from IPython.zmq.kernelmanagerabc import ('
26 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
27
27
28 class InProcessChannel(object):
28 class InProcessChannel(object):
29 """ Base class for in-process channels.
29 """Base class for in-process channels."""
30 """
31
30
32 def __init__(self, manager):
31 def __init__(self, manager):
33 super(InProcessChannel, self).__init__()
32 super(InProcessChannel, self).__init__()
@@ -77,8 +76,7 b' class InProcessChannel(object):'
77
76
78
77
79 class InProcessShellChannel(InProcessChannel):
78 class InProcessShellChannel(InProcessChannel):
80 """The DEALER channel for issues request/replies to the kernel.
79 """See `IPython.zmq.kernelmanager.ShellChannel` for docstrings."""
81 """
82
80
83 # flag for whether execute requests should be allowed to call raw_input
81 # flag for whether execute requests should be allowed to call raw_input
84 allow_stdin = True
82 allow_stdin = True
@@ -89,42 +87,6 b' class InProcessShellChannel(InProcessChannel):'
89
87
90 def execute(self, code, silent=False, store_history=True,
88 def execute(self, code, silent=False, store_history=True,
91 user_variables=[], user_expressions={}, allow_stdin=None):
89 user_variables=[], user_expressions={}, allow_stdin=None):
92 """Execute code in the kernel.
93
94 Parameters
95 ----------
96 code : str
97 A string of Python code.
98
99 silent : bool, optional (default False)
100 If set, the kernel will execute the code as quietly possible, and
101 will force store_history to be False.
102
103 store_history : bool, optional (default True)
104 If set, the kernel will store command history. This is forced
105 to be False if silent is True.
106
107 user_variables : list, optional
108 A list of variable names to pull from the user's namespace. They
109 will come back as a dict with these names as keys and their
110 :func:`repr` as values.
111
112 user_expressions : dict, optional
113 A dict mapping names to expressions to be evaluated in the user's
114 dict. The expression values are returned as strings formatted using
115 :func:`repr`.
116
117 allow_stdin : bool, optional (default self.allow_stdin)
118 Flag for whether the kernel can send stdin requests to frontends.
119
120 Some frontends (e.g. the Notebook) do not support stdin requests.
121 If raw_input is called from code executed from such a frontend, a
122 StdinNotImplementedError will be raised.
123
124 Returns
125 -------
126 The msg_id of the message sent.
127 """
128 if allow_stdin is None:
90 if allow_stdin is None:
129 allow_stdin = self.allow_stdin
91 allow_stdin = self.allow_stdin
130 content = dict(code=code, silent=silent, store_history=store_history,
92 content = dict(code=code, silent=silent, store_history=store_history,
@@ -136,81 +98,18 b' class InProcessShellChannel(InProcessChannel):'
136 return msg['header']['msg_id']
98 return msg['header']['msg_id']
137
99
138 def complete(self, text, line, cursor_pos, block=None):
100 def complete(self, text, line, cursor_pos, block=None):
139 """Tab complete text in the kernel's namespace.
140
141 Parameters
142 ----------
143 text : str
144 The text to complete.
145 line : str
146 The full line of text that is the surrounding context for the
147 text to complete.
148 cursor_pos : int
149 The position of the cursor in the line where the completion was
150 requested.
151 block : str, optional
152 The full block of code in which the completion is being requested.
153
154 Returns
155 -------
156 The msg_id of the message sent.
157 """
158 content = dict(text=text, line=line, block=block, cursor_pos=cursor_pos)
101 content = dict(text=text, line=line, block=block, cursor_pos=cursor_pos)
159 msg = self.manager.session.msg('complete_request', content)
102 msg = self.manager.session.msg('complete_request', content)
160 self._dispatch_to_kernel(msg)
103 self._dispatch_to_kernel(msg)
161 return msg['header']['msg_id']
104 return msg['header']['msg_id']
162
105
163 def object_info(self, oname, detail_level=0):
106 def object_info(self, oname, detail_level=0):
164 """Get metadata information about an object.
165
166 Parameters
167 ----------
168 oname : str
169 A string specifying the object name.
170 detail_level : int, optional
171 The level of detail for the introspection (0-2)
172
173 Returns
174 -------
175 The msg_id of the message sent.
176 """
177 content = dict(oname=oname, detail_level=detail_level)
107 content = dict(oname=oname, detail_level=detail_level)
178 msg = self.manager.session.msg('object_info_request', content)
108 msg = self.manager.session.msg('object_info_request', content)
179 self._dispatch_to_kernel(msg)
109 self._dispatch_to_kernel(msg)
180 return msg['header']['msg_id']
110 return msg['header']['msg_id']
181
111
182 def history(self, raw=True, output=False, hist_access_type='range', **kwds):
112 def history(self, raw=True, output=False, hist_access_type='range', **kwds):
183 """Get entries from the history list.
184
185 Parameters
186 ----------
187 raw : bool
188 If True, return the raw input.
189 output : bool
190 If True, then return the output as well.
191 hist_access_type : str
192 'range' (fill in session, start and stop params), 'tail' (fill in n)
193 or 'search' (fill in pattern param).
194
195 session : int
196 For a range request, the session from which to get lines. Session
197 numbers are positive integers; negative ones count back from the
198 current session.
199 start : int
200 The first line number of a history range.
201 stop : int
202 The final (excluded) line number of a history range.
203
204 n : int
205 The number of lines of history to get for a tail request.
206
207 pattern : str
208 The glob-syntax pattern for a search request.
209
210 Returns
211 -------
212 The msg_id of the message sent.
213 """
214 content = dict(raw=raw, output=output,
113 content = dict(raw=raw, output=output,
215 hist_access_type=hist_access_type, **kwds)
114 hist_access_type=hist_access_type, **kwds)
216 msg = self.manager.session.msg('history_request', content)
115 msg = self.manager.session.msg('history_request', content)
@@ -218,10 +117,6 b' class InProcessShellChannel(InProcessChannel):'
218 return msg['header']['msg_id']
117 return msg['header']['msg_id']
219
118
220 def shutdown(self, restart=False):
119 def shutdown(self, restart=False):
221 """ Request an immediate kernel shutdown.
222
223 A dummy method for the in-process kernel.
224 """
225 # FIXME: What to do here?
120 # FIXME: What to do here?
226 raise NotImplementedError('Cannot shutdown in-process kernel')
121 raise NotImplementedError('Cannot shutdown in-process kernel')
227
122
@@ -246,23 +141,16 b' class InProcessShellChannel(InProcessChannel):'
246
141
247
142
248 class InProcessIOPubChannel(InProcessChannel):
143 class InProcessIOPubChannel(InProcessChannel):
249 """The SUB channel which listens for messages that the kernel publishes.
144 """See `IPython.zmq.kernelmanager.IOPubChannel` for docstrings."""
250 """
251
145
252 def flush(self, timeout=1.0):
146 def flush(self, timeout=1.0):
253 """ Immediately processes all pending messages on the SUB channel.
254
255 A dummy method for the in-process kernel.
256 """
257 pass
147 pass
258
148
259
149
260 class InProcessStdInChannel(InProcessChannel):
150 class InProcessStdInChannel(InProcessChannel):
261 """ A reply channel to handle raw_input requests that the kernel makes. """
151 """See `IPython.zmq.kernelmanager.StdInChannel` for docstrings."""
262
152
263 def input(self, string):
153 def input(self, string):
264 """ Send a string of raw input to the kernel.
265 """
266 kernel = self.manager.kernel
154 kernel = self.manager.kernel
267 if kernel is None:
155 if kernel is None:
268 raise RuntimeError('Cannot send input reply. No kernel exists.')
156 raise RuntimeError('Cannot send input reply. No kernel exists.')
@@ -270,7 +158,7 b' class InProcessStdInChannel(InProcessChannel):'
270
158
271
159
272 class InProcessHBChannel(InProcessChannel):
160 class InProcessHBChannel(InProcessChannel):
273 """ A dummy heartbeat channel. """
161 """See `IPython.zmq.kernelmanager.HBChannel` for docstrings."""
274
162
275 time_to_dead = 3.0
163 time_to_dead = 3.0
276
164
@@ -279,15 +167,12 b' class InProcessHBChannel(InProcessChannel):'
279 self._pause = True
167 self._pause = True
280
168
281 def pause(self):
169 def pause(self):
282 """ Pause the heartbeat. """
283 self._pause = True
170 self._pause = True
284
171
285 def unpause(self):
172 def unpause(self):
286 """ Unpause the heartbeat. """
287 self._pause = False
173 self._pause = False
288
174
289 def is_beating(self):
175 def is_beating(self):
290 """ Is the heartbeat running and responsive (and not paused). """
291 return not self._pause
176 return not self._pause
292
177
293
178
@@ -296,11 +181,13 b' class InProcessHBChannel(InProcessChannel):'
296 #-----------------------------------------------------------------------------
181 #-----------------------------------------------------------------------------
297
182
298 class InProcessKernelManager(Configurable):
183 class InProcessKernelManager(Configurable):
299 """ A manager for an in-process kernel.
184 """A manager for an in-process kernel.
300
185
301 This class implements most of the interface of
186 This class implements the interface of
302 ``IPython.zmq.kernelmanager.KernelManager`` and allows (asynchronous)
187 `IPython.zmq.kernelmanagerabc.KernelManagerABC` and allows
303 frontends to be used seamlessly with an in-process kernel.
188 (asynchronous) frontends to be used seamlessly with an in-process kernel.
189
190 See `IPython.zmq.kernelmanager.KernelManager` for docstrings.
304 """
191 """
305
192
306 # The Session to use for building messages.
193 # The Session to use for building messages.
@@ -329,8 +216,6 b' class InProcessKernelManager(Configurable):'
329 #--------------------------------------------------------------------------
216 #--------------------------------------------------------------------------
330
217
331 def start_channels(self, shell=True, iopub=True, stdin=True, hb=True):
218 def start_channels(self, shell=True, iopub=True, stdin=True, hb=True):
332 """ Starts the channels for this kernel.
333 """
334 if shell:
219 if shell:
335 self.shell_channel.start()
220 self.shell_channel.start()
336 if iopub:
221 if iopub:
@@ -344,8 +229,6 b' class InProcessKernelManager(Configurable):'
344 self.hb_channel.start()
229 self.hb_channel.start()
345
230
346 def stop_channels(self):
231 def stop_channels(self):
347 """ Stops all the running channels for this kernel.
348 """
349 if self.shell_channel.is_alive():
232 if self.shell_channel.is_alive():
350 self.shell_channel.stop()
233 self.shell_channel.stop()
351 if self.iopub_channel.is_alive():
234 if self.iopub_channel.is_alive():
@@ -357,35 +240,29 b' class InProcessKernelManager(Configurable):'
357
240
358 @property
241 @property
359 def channels_running(self):
242 def channels_running(self):
360 """ Are any of the channels created and running? """
361 return (self.shell_channel.is_alive() or self.iopub_channel.is_alive() or
243 return (self.shell_channel.is_alive() or self.iopub_channel.is_alive() or
362 self.stdin_channel.is_alive() or self.hb_channel.is_alive())
244 self.stdin_channel.is_alive() or self.hb_channel.is_alive())
363
245
364 @property
246 @property
365 def shell_channel(self):
247 def shell_channel(self):
366 """Get the REQ socket channel object to make requests of the kernel."""
367 if self._shell_channel is None:
248 if self._shell_channel is None:
368 self._shell_channel = self.shell_channel_class(self)
249 self._shell_channel = self.shell_channel_class(self)
369 return self._shell_channel
250 return self._shell_channel
370
251
371 @property
252 @property
372 def iopub_channel(self):
253 def iopub_channel(self):
373 """Get the SUB socket channel object."""
374 if self._iopub_channel is None:
254 if self._iopub_channel is None:
375 self._iopub_channel = self.iopub_channel_class(self)
255 self._iopub_channel = self.iopub_channel_class(self)
376 return self._iopub_channel
256 return self._iopub_channel
377
257
378 @property
258 @property
379 def stdin_channel(self):
259 def stdin_channel(self):
380 """Get the REP socket channel object to handle stdin (raw_input)."""
381 if self._stdin_channel is None:
260 if self._stdin_channel is None:
382 self._stdin_channel = self.stdin_channel_class(self)
261 self._stdin_channel = self.stdin_channel_class(self)
383 return self._stdin_channel
262 return self._stdin_channel
384
263
385 @property
264 @property
386 def hb_channel(self):
265 def hb_channel(self):
387 """Get the heartbeat socket channel object to check that the
388 kernel is alive."""
389 if self._hb_channel is None:
266 if self._hb_channel is None:
390 self._hb_channel = self.hb_channel_class(self)
267 self._hb_channel = self.hb_channel_class(self)
391 return self._hb_channel
268 return self._hb_channel
@@ -395,50 +272,33 b' class InProcessKernelManager(Configurable):'
395 #--------------------------------------------------------------------------
272 #--------------------------------------------------------------------------
396
273
397 def start_kernel(self, **kwds):
274 def start_kernel(self, **kwds):
398 """ Starts a kernel process and configures the manager to use it.
399 """
400 from IPython.inprocess.ipkernel import InProcessKernel
275 from IPython.inprocess.ipkernel import InProcessKernel
401 self.kernel = InProcessKernel()
276 self.kernel = InProcessKernel()
402 self.kernel.frontends.append(self)
277 self.kernel.frontends.append(self)
403
278
404 def shutdown_kernel(self):
279 def shutdown_kernel(self):
405 """ Attempts to the stop the kernel process cleanly. If the kernel
406 cannot be stopped and the kernel is local, it is killed.
407 """
408 self.kill_kernel()
280 self.kill_kernel()
409
281
410 def restart_kernel(self, now=False, **kwds):
282 def restart_kernel(self, now=False, **kwds):
411 """ Restarts a kernel with the arguments that were used to launch it.
412
413 The 'now' parameter is ignored.
414 """
415 self.shutdown_kernel()
283 self.shutdown_kernel()
416 self.start_kernel(**kwds)
284 self.start_kernel(**kwds)
417
285
418 @property
286 @property
419 def has_kernel(self):
287 def has_kernel(self):
420 """ Returns whether a kernel process has been specified for the kernel
421 manager.
422 """
423 return self.kernel is not None
288 return self.kernel is not None
424
289
425 def kill_kernel(self):
290 def kill_kernel(self):
426 """ Kill the running kernel.
427 """
428 self.kernel.frontends.remove(self)
291 self.kernel.frontends.remove(self)
429 self.kernel = None
292 self.kernel = None
430
293
431 def interrupt_kernel(self):
294 def interrupt_kernel(self):
432 """ Interrupts the kernel. """
433 raise NotImplementedError("Cannot interrupt in-process kernel.")
295 raise NotImplementedError("Cannot interrupt in-process kernel.")
434
296
435 def signal_kernel(self, signum):
297 def signal_kernel(self, signum):
436 """ Sends a signal to the kernel. """
437 raise NotImplementedError("Cannot signal in-process kernel.")
298 raise NotImplementedError("Cannot signal in-process kernel.")
438
299
439 @property
300 @property
440 def is_alive(self):
301 def is_alive(self):
441 """ Is the kernel process still running? """
442 return True
302 return True
443
303
444
304
@@ -38,7 +38,11 b' class ChannelABC(object):'
38
38
39
39
40 class ShellChannelABC(ChannelABC):
40 class ShellChannelABC(ChannelABC):
41 """The DEALER channel for issues request/replies to the kernel.
41 """ShellChannel ABC.
42
43 The docstrings for this class can be found in the base implementation:
44
45 `IPython.zmq.kernelmanager.ShellChannel`
42 """
46 """
43
47
44 @abc.abstractproperty
48 @abc.abstractproperty
@@ -48,173 +52,62 b' class ShellChannelABC(ChannelABC):'
48 @abc.abstractmethod
52 @abc.abstractmethod
49 def execute(self, code, silent=False, store_history=True,
53 def execute(self, code, silent=False, store_history=True,
50 user_variables=None, user_expressions=None, allow_stdin=None):
54 user_variables=None, user_expressions=None, allow_stdin=None):
51 """Execute code in the kernel.
52
53 Parameters
54 ----------
55 code : str
56 A string of Python code.
57
58 silent : bool, optional (default False)
59 If set, the kernel will execute the code as quietly possible, and
60 will force store_history to be False.
61
62 store_history : bool, optional (default True)
63 If set, the kernel will store command history. This is forced
64 to be False if silent is True.
65
66 user_variables : list, optional
67 A list of variable names to pull from the user's namespace. They
68 will come back as a dict with these names as keys and their
69 :func:`repr` as values.
70
71 user_expressions : dict, optional
72 A dict mapping names to expressions to be evaluated in the user's
73 dict. The expression values are returned as strings formatted using
74 :func:`repr`.
75
76 allow_stdin : bool, optional (default self.allow_stdin)
77 Flag for whether the kernel can send stdin requests to frontends.
78
79 Some frontends (e.g. the Notebook) do not support stdin requests.
80 If raw_input is called from code executed from such a frontend, a
81 StdinNotImplementedError will be raised.
82
83 Returns
84 -------
85 The msg_id of the message sent.
86 """
87 pass
55 pass
88
56
89 @abc.abstractmethod
57 @abc.abstractmethod
90 def complete(self, text, line, cursor_pos, block=None):
58 def complete(self, text, line, cursor_pos, block=None):
91 """Tab complete text in the kernel's namespace.
92
93 Parameters
94 ----------
95 text : str
96 The text to complete.
97 line : str
98 The full line of text that is the surrounding context for the
99 text to complete.
100 cursor_pos : int
101 The position of the cursor in the line where the completion was
102 requested.
103 block : str, optional
104 The full block of code in which the completion is being requested.
105
106 Returns
107 -------
108 The msg_id of the message sent.
109 """
110 pass
59 pass
111
60
112 @abc.abstractmethod
61 @abc.abstractmethod
113 def object_info(self, oname, detail_level=0):
62 def object_info(self, oname, detail_level=0):
114 """Get metadata information about an object.
115
116 Parameters
117 ----------
118 oname : str
119 A string specifying the object name.
120 detail_level : int, optional
121 The level of detail for the introspection (0-2)
122
123 Returns
124 -------
125 The msg_id of the message sent.
126 """
127 pass
63 pass
128
64
129 @abc.abstractmethod
65 @abc.abstractmethod
130 def history(self, raw=True, output=False, hist_access_type='range', **kwargs):
66 def history(self, raw=True, output=False, hist_access_type='range', **kwargs):
131 """Get entries from the history list.
132
133 Parameters
134 ----------
135 raw : bool
136 If True, return the raw input.
137 output : bool
138 If True, then return the output as well.
139 hist_access_type : str
140 'range' (fill in session, start and stop params), 'tail' (fill in n)
141 or 'search' (fill in pattern param).
142
143 session : int
144 For a range request, the session from which to get lines. Session
145 numbers are positive integers; negative ones count back from the
146 current session.
147 start : int
148 The first line number of a history range.
149 stop : int
150 The final (excluded) line number of a history range.
151
152 n : int
153 The number of lines of history to get for a tail request.
154
155 pattern : str
156 The glob-syntax pattern for a search request.
157
158 Returns
159 -------
160 The msg_id of the message sent.
161 """
162 pass
67 pass
163
68
164 @abc.abstractmethod
69 @abc.abstractmethod
165 def kernel_info(self):
70 def kernel_info(self):
166 """Request kernel info."""
167 pass
71 pass
168
72
169 @abc.abstractmethod
73 @abc.abstractmethod
170 def shutdown(self, restart=False):
74 def shutdown(self, restart=False):
171 """Request an immediate kernel shutdown.
172
173 Upon receipt of the (empty) reply, client code can safely assume that
174 the kernel has shut down and it's safe to forcefully terminate it if
175 it's still alive.
176
177 The kernel will send the reply via a function registered with Python's
178 atexit module, ensuring it's truly done as the kernel is done with all
179 normal operation.
180 """
181 pass
75 pass
182
76
183
77
184 class IOPubChannelABC(ChannelABC):
78 class IOPubChannelABC(ChannelABC):
185 """The SUB channel which listens for messages that the kernel publishes."""
79 """IOPubChannel ABC.
80
81 The docstrings for this class can be found in the base implementation:
186
82
83 `IPython.zmq.kernelmanager.IOPubChannel`
84 """
187
85
188 @abc.abstractmethod
86 @abc.abstractmethod
189 def flush(self, timeout=1.0):
87 def flush(self, timeout=1.0):
190 """Immediately processes all pending messages on the SUB channel.
191
192 Callers should use this method to ensure that :method:`call_handlers`
193 has been called for all messages that have been received on the
194 0MQ SUB socket of this channel.
195
196 This method is thread safe.
197
198 Parameters
199 ----------
200 timeout : float, optional
201 The maximum amount of time to spend flushing, in seconds. The
202 default is one second.
203 """
204 pass
88 pass
205
89
206
90
207 class StdInChannelABC(ChannelABC):
91 class StdInChannelABC(ChannelABC):
208 """A reply channel to handle raw_input requests that the kernel makes."""
92 """StdInChannel ABC.
93
94 The docstrings for this class can be found in the base implementation:
95
96 `IPython.zmq.kernelmanager.StdInChannel`
97 """
209
98
210 @abc.abstractmethod
99 @abc.abstractmethod
211 def input(self, string):
100 def input(self, string):
212 """Send a string of raw input to the kernel."""
213 pass
101 pass
214
102
215
103
216 class HBChannelABC(ChannelABC):
104 class HBChannelABC(ChannelABC):
217 """The heartbeat channel which monitors the kernel heartbeat."""
105 """HBChannel ABC.
106
107 The docstrings for this class can be found in the base implementation:
108
109 `IPython.zmq.kernelmanager.HBChannel`
110 """
218
111
219 @abc.abstractproperty
112 @abc.abstractproperty
220 def time_to_dead(self):
113 def time_to_dead(self):
@@ -222,17 +115,14 b' class HBChannelABC(ChannelABC):'
222
115
223 @abc.abstractmethod
116 @abc.abstractmethod
224 def pause(self):
117 def pause(self):
225 """Pause the heartbeat."""
226 pass
118 pass
227
119
228 @abc.abstractmethod
120 @abc.abstractmethod
229 def unpause(self):
121 def unpause(self):
230 """Unpause the heartbeat."""
231 pass
122 pass
232
123
233 @abc.abstractmethod
124 @abc.abstractmethod
234 def is_beating(self):
125 def is_beating(self):
235 """Is the heartbeat running and responsive (and not paused)."""
236 pass
126 pass
237
127
238
128
@@ -241,7 +131,12 b' class HBChannelABC(ChannelABC):'
241 #-----------------------------------------------------------------------------
131 #-----------------------------------------------------------------------------
242
132
243 class KernelManagerABC(object):
133 class KernelManagerABC(object):
244 """ Manages a kernel for a frontend."""
134 """KernelManager ABC.
135
136 The docstrings for this class can be found in the base implementation:
137
138 `IPython.zmq.kernelmanager.KernelManager`
139 """
245
140
246 __metaclass__ = abc.ABCMeta
141 __metaclass__ = abc.ABCMeta
247
142
@@ -271,44 +166,30 b' class KernelManagerABC(object):'
271
166
272 @abc.abstractmethod
167 @abc.abstractmethod
273 def start_channels(self, shell=True, iopub=True, stdin=True, hb=True):
168 def start_channels(self, shell=True, iopub=True, stdin=True, hb=True):
274 """Starts the channels for this kernel.
275
276 This will create the channels if they do not exist and then start
277 them. If port numbers of 0 are being used (random ports) then you
278 must first call :method:`start_kernel`. If the channels have been
279 stopped and you call this, :class:`RuntimeError` will be raised.
280 """
281 pass
169 pass
282
170
283 @abc.abstractmethod
171 @abc.abstractmethod
284 def stop_channels(self):
172 def stop_channels(self):
285 """Stops all the running channels for this kernel."""
286 pass
173 pass
287
174
288 @abc.abstractproperty
175 @abc.abstractproperty
289 def channels_running(self):
176 def channels_running(self):
290 """Are any of the channels created and running?"""
291 pass
177 pass
292
178
293 @abc.abstractproperty
179 @abc.abstractproperty
294 def shell_channel(self):
180 def shell_channel(self):
295 """Get the REQ socket channel object to make requests of the kernel."""
296 pass
181 pass
297
182
298 @abc.abstractproperty
183 @abc.abstractproperty
299 def iopub_channel(self):
184 def iopub_channel(self):
300 """Get the SUB socket channel object."""
301 pass
185 pass
302
186
303 @abc.abstractproperty
187 @abc.abstractproperty
304 def stdin_channel(self):
188 def stdin_channel(self):
305 """Get the REP socket channel object to handle stdin (raw_input)."""
306 pass
189 pass
307
190
308 @abc.abstractproperty
191 @abc.abstractproperty
309 def hb_channel(self):
192 def hb_channel(self):
310 """Get the heartbeat socket channel object to check that the
311 kernel is alive."""
312 pass
193 pass
313
194
314 #--------------------------------------------------------------------------
195 #--------------------------------------------------------------------------
@@ -317,85 +198,32 b' class KernelManagerABC(object):'
317
198
318 @abc.abstractmethod
199 @abc.abstractmethod
319 def start_kernel(self, **kw):
200 def start_kernel(self, **kw):
320 """Starts a kernel process and configures the manager to use it.
321
322 If random ports (port=0) are being used, this method must be called
323 before the channels are created.
324
325 Parameters:
326 -----------
327 launcher : callable, optional (default None)
328 A custom function for launching the kernel process (generally a
329 wrapper around ``entry_point.base_launch_kernel``). In most cases,
330 it should not be necessary to use this parameter.
331
332 **kw : optional
333 See respective options for IPython and Python kernels.
334 """
335 pass
201 pass
336
202
337 @abc.abstractmethod
203 @abc.abstractmethod
338 def shutdown_kernel(self, now=False, restart=False):
204 def shutdown_kernel(self, now=False, restart=False):
339 """ Attempts to the stop the kernel process cleanly."""
340 pass
205 pass
341
206
342 @abc.abstractmethod
207 @abc.abstractmethod
343 def restart_kernel(self, now=False, **kw):
208 def restart_kernel(self, now=False, **kw):
344 """Restarts a kernel with the arguments that were used to launch it.
345
346 If the old kernel was launched with random ports, the same ports will be
347 used for the new kernel.
348
349 Parameters
350 ----------
351 now : bool, optional
352 If True, the kernel is forcefully restarted *immediately*, without
353 having a chance to do any cleanup action. Otherwise the kernel is
354 given 1s to clean up before a forceful restart is issued.
355
356 In all cases the kernel is restarted, the only difference is whether
357 it is given a chance to perform a clean shutdown or not.
358
359 **kw : optional
360 Any options specified here will replace those used to launch the
361 kernel.
362 """
363 pass
209 pass
364
210
365 @abc.abstractproperty
211 @abc.abstractproperty
366 def has_kernel(self):
212 def has_kernel(self):
367 """Returns whether a kernel process has been specified for the kernel
368 manager.
369 """
370 pass
213 pass
371
214
372 @abc.abstractmethod
215 @abc.abstractmethod
373 def kill_kernel(self):
216 def kill_kernel(self):
374 """ Kill the running kernel.
375
376 This method blocks until the kernel process has terminated.
377 """
378 pass
217 pass
379
218
380 @abc.abstractmethod
219 @abc.abstractmethod
381 def interrupt_kernel(self):
220 def interrupt_kernel(self):
382 """ Interrupts the kernel.
383
384 Unlike ``signal_kernel``, this operation is well supported on all
385 platforms.
386 """
387 pass
221 pass
388
222
389 @abc.abstractmethod
223 @abc.abstractmethod
390 def signal_kernel(self, signum):
224 def signal_kernel(self, signum):
391 """ Sends a signal to the kernel.
392
393 Note that since only SIGTERM is supported on Windows, this function is
394 only useful on Unix systems.
395 """
396 pass
225 pass
397
226
398 @abc.abstractproperty
227 @abc.abstractproperty
399 def is_alive(self):
228 def is_alive(self):
400 """Is the kernel process still running?"""
401 pass
229 pass
General Comments 0
You need to be logged in to leave comments. Login now