Show More
@@ -30,8 +30,8 b' class BaseFrontendMixin(object):' | |||||
30 |
|
30 | |||
31 | # Disconnect the old kernel manager's channels. |
|
31 | # Disconnect the old kernel manager's channels. | |
32 | old_manager.sub_channel.message_received.disconnect(self._dispatch) |
|
32 | old_manager.sub_channel.message_received.disconnect(self._dispatch) | |
33 |
old_manager. |
|
33 | old_manager.shell_channel.message_received.disconnect(self._dispatch) | |
34 |
old_manager. |
|
34 | old_manager.stdin_channel.message_received.disconnect(self._dispatch) | |
35 | old_manager.hb_channel.kernel_died.disconnect( |
|
35 | old_manager.hb_channel.kernel_died.disconnect( | |
36 | self._handle_kernel_died) |
|
36 | self._handle_kernel_died) | |
37 |
|
37 | |||
@@ -50,8 +50,8 b' class BaseFrontendMixin(object):' | |||||
50 |
|
50 | |||
51 | # Connect the new kernel manager's channels. |
|
51 | # Connect the new kernel manager's channels. | |
52 | kernel_manager.sub_channel.message_received.connect(self._dispatch) |
|
52 | kernel_manager.sub_channel.message_received.connect(self._dispatch) | |
53 |
kernel_manager. |
|
53 | kernel_manager.shell_channel.message_received.connect(self._dispatch) | |
54 |
kernel_manager. |
|
54 | kernel_manager.stdin_channel.message_received.connect(self._dispatch) | |
55 | kernel_manager.hb_channel.kernel_died.connect(self._handle_kernel_died) |
|
55 | kernel_manager.hb_channel.kernel_died.connect(self._handle_kernel_died) | |
56 |
|
56 | |||
57 | # Handle the case where the kernel manager started channels before |
|
57 | # Handle the case where the kernel manager started channels before |
@@ -184,7 +184,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
184 |
|
184 | |||
185 | See parent class :meth:`execute` docstring for full details. |
|
185 | See parent class :meth:`execute` docstring for full details. | |
186 | """ |
|
186 | """ | |
187 |
msg_id = self.kernel_manager. |
|
187 | msg_id = self.kernel_manager.shell_channel.execute(source, hidden) | |
188 | self._request_info['execute'] = self._ExecutionRequest(msg_id, 'user') |
|
188 | self._request_info['execute'] = self._ExecutionRequest(msg_id, 'user') | |
189 | self._hidden = hidden |
|
189 | self._hidden = hidden | |
190 | if not hidden: |
|
190 | if not hidden: | |
@@ -330,7 +330,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
330 | self.kernel_manager.sub_channel.flush() |
|
330 | self.kernel_manager.sub_channel.flush() | |
331 |
|
331 | |||
332 | def callback(line): |
|
332 | def callback(line): | |
333 |
self.kernel_manager. |
|
333 | self.kernel_manager.stdin_channel.input(line) | |
334 | self._readline(msg['content']['prompt'], callback=callback) |
|
334 | self._readline(msg['content']['prompt'], callback=callback) | |
335 |
|
335 | |||
336 | def _handle_kernel_died(self, since_last_heartbeat): |
|
336 | def _handle_kernel_died(self, since_last_heartbeat): | |
@@ -527,7 +527,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
527 |
|
527 | |||
528 | # Send the metadata request to the kernel |
|
528 | # Send the metadata request to the kernel | |
529 | name = '.'.join(context) |
|
529 | name = '.'.join(context) | |
530 |
msg_id = self.kernel_manager. |
|
530 | msg_id = self.kernel_manager.shell_channel.object_info(name) | |
531 | pos = self._get_cursor().position() |
|
531 | pos = self._get_cursor().position() | |
532 | self._request_info['call_tip'] = self._CallTipRequest(msg_id, pos) |
|
532 | self._request_info['call_tip'] = self._CallTipRequest(msg_id, pos) | |
533 | return True |
|
533 | return True | |
@@ -538,7 +538,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
538 | context = self._get_context() |
|
538 | context = self._get_context() | |
539 | if context: |
|
539 | if context: | |
540 | # Send the completion request to the kernel |
|
540 | # Send the completion request to the kernel | |
541 |
msg_id = self.kernel_manager. |
|
541 | msg_id = self.kernel_manager.shell_channel.complete( | |
542 | '.'.join(context), # text |
|
542 | '.'.join(context), # text | |
543 | self._get_input_buffer_cursor_line(), # line |
|
543 | self._get_input_buffer_cursor_line(), # line | |
544 | self._get_input_buffer_cursor_column(), # cursor_pos |
|
544 | self._get_input_buffer_cursor_column(), # cursor_pos |
@@ -222,7 +222,7 b' class IPythonWidget(FrontendWidget):' | |||||
222 | """ Reimplemented to make a history request. |
|
222 | """ Reimplemented to make a history request. | |
223 | """ |
|
223 | """ | |
224 | super(IPythonWidget, self)._started_channels() |
|
224 | super(IPythonWidget, self)._started_channels() | |
225 |
self.kernel_manager. |
|
225 | self.kernel_manager.shell_channel.history(hist_access_type='tail', n=1000) | |
226 |
|
226 | |||
227 | #--------------------------------------------------------------------------- |
|
227 | #--------------------------------------------------------------------------- | |
228 | # 'ConsoleWidget' public interface |
|
228 | # 'ConsoleWidget' public interface | |
@@ -264,7 +264,7 b' class IPythonWidget(FrontendWidget):' | |||||
264 | text = '' |
|
264 | text = '' | |
265 |
|
265 | |||
266 | # Send the completion request to the kernel |
|
266 | # Send the completion request to the kernel | |
267 |
msg_id = self.kernel_manager. |
|
267 | msg_id = self.kernel_manager.shell_channel.complete( | |
268 | text, # text |
|
268 | text, # text | |
269 | self._get_input_buffer_cursor_line(), # line |
|
269 | self._get_input_buffer_cursor_line(), # line | |
270 | self._get_input_buffer_cursor_column(), # cursor_pos |
|
270 | self._get_input_buffer_cursor_column(), # cursor_pos | |
@@ -315,7 +315,7 b' class IPythonWidget(FrontendWidget):' | |||||
315 | """ |
|
315 | """ | |
316 | # If a number was not specified, make a prompt number request. |
|
316 | # If a number was not specified, make a prompt number request. | |
317 | if number is None: |
|
317 | if number is None: | |
318 |
msg_id = self.kernel_manager. |
|
318 | msg_id = self.kernel_manager.shell_channel.execute('', silent=True) | |
319 | info = self._ExecutionRequest(msg_id, 'prompt') |
|
319 | info = self._ExecutionRequest(msg_id, 'prompt') | |
320 | self._request_info['execute'] = info |
|
320 | self._request_info['execute'] = info | |
321 | return |
|
321 | return |
@@ -257,9 +257,9 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
257 |
|
257 | |||
258 | # Create a KernelManager and start a kernel. |
|
258 | # Create a KernelManager and start a kernel. | |
259 | self.kernel_manager = QtKernelManager( |
|
259 | self.kernel_manager = QtKernelManager( | |
260 |
|
|
260 | shell_address=(self.ip, self.shell_port), | |
261 | sub_address=(self.ip, self.iopub_port), |
|
261 | sub_address=(self.ip, self.iopub_port), | |
262 |
|
|
262 | stdin_address=(self.ip, self.stdin_port), | |
263 | hb_address=(self.ip, self.hb_port) |
|
263 | hb_address=(self.ip, self.hb_port) | |
264 | ) |
|
264 | ) | |
265 | # start the kernel |
|
265 | # start the kernel |
@@ -7,7 +7,7 b' from IPython.external.qt import QtCore' | |||||
7 | # IPython imports. |
|
7 | # IPython imports. | |
8 | from IPython.utils.traitlets import Type |
|
8 | from IPython.utils.traitlets import Type | |
9 | from IPython.zmq.kernelmanager import KernelManager, SubSocketChannel, \ |
|
9 | from IPython.zmq.kernelmanager import KernelManager, SubSocketChannel, \ | |
10 |
|
|
10 | ShellSocketChannel, StdInSocketChannel, HBSocketChannel | |
11 | from util import MetaQObjectHasTraits, SuperQObject |
|
11 | from util import MetaQObjectHasTraits, SuperQObject | |
12 |
|
12 | |||
13 |
|
13 | |||
@@ -20,7 +20,7 b' class SocketChannelQObject(SuperQObject):' | |||||
20 | stopped = QtCore.Signal() |
|
20 | stopped = QtCore.Signal() | |
21 |
|
21 | |||
22 | #--------------------------------------------------------------------------- |
|
22 | #--------------------------------------------------------------------------- | |
23 |
# 'Z |
|
23 | # 'ZMQSocketChannel' interface | |
24 | #--------------------------------------------------------------------------- |
|
24 | #--------------------------------------------------------------------------- | |
25 |
|
25 | |||
26 | def start(self): |
|
26 | def start(self): | |
@@ -36,7 +36,7 b' class SocketChannelQObject(SuperQObject):' | |||||
36 | self.stopped.emit() |
|
36 | self.stopped.emit() | |
37 |
|
37 | |||
38 |
|
38 | |||
39 |
class Qt |
|
39 | class QtShellSocketChannel(SocketChannelQObject, ShellSocketChannel): | |
40 |
|
40 | |||
41 | # Emitted when any message is received. |
|
41 | # Emitted when any message is received. | |
42 | message_received = QtCore.Signal(object) |
|
42 | message_received = QtCore.Signal(object) | |
@@ -56,7 +56,7 b' class QtXReqSocketChannel(SocketChannelQObject, XReqSocketChannel):' | |||||
56 | _handlers_called = False |
|
56 | _handlers_called = False | |
57 |
|
57 | |||
58 | #--------------------------------------------------------------------------- |
|
58 | #--------------------------------------------------------------------------- | |
59 |
# ' |
|
59 | # 'ShellSocketChannel' interface | |
60 | #--------------------------------------------------------------------------- |
|
60 | #--------------------------------------------------------------------------- | |
61 |
|
61 | |||
62 | def call_handlers(self, msg): |
|
62 | def call_handlers(self, msg): | |
@@ -76,7 +76,7 b' class QtXReqSocketChannel(SocketChannelQObject, XReqSocketChannel):' | |||||
76 | self._handlers_called = True |
|
76 | self._handlers_called = True | |
77 |
|
77 | |||
78 | #--------------------------------------------------------------------------- |
|
78 | #--------------------------------------------------------------------------- | |
79 |
# 'Qt |
|
79 | # 'QtShellSocketChannel' interface | |
80 | #--------------------------------------------------------------------------- |
|
80 | #--------------------------------------------------------------------------- | |
81 |
|
81 | |||
82 | def reset_first_reply(self): |
|
82 | def reset_first_reply(self): | |
@@ -136,7 +136,7 b' class QtSubSocketChannel(SocketChannelQObject, SubSocketChannel):' | |||||
136 | QtCore.QCoreApplication.instance().processEvents() |
|
136 | QtCore.QCoreApplication.instance().processEvents() | |
137 |
|
137 | |||
138 |
|
138 | |||
139 |
class Qt |
|
139 | class QtStdInSocketChannel(SocketChannelQObject, StdInSocketChannel): | |
140 |
|
140 | |||
141 | # Emitted when any message is received. |
|
141 | # Emitted when any message is received. | |
142 | message_received = QtCore.Signal(object) |
|
142 | message_received = QtCore.Signal(object) | |
@@ -145,7 +145,7 b' class QtRepSocketChannel(SocketChannelQObject, RepSocketChannel):' | |||||
145 | input_requested = QtCore.Signal(object) |
|
145 | input_requested = QtCore.Signal(object) | |
146 |
|
146 | |||
147 | #--------------------------------------------------------------------------- |
|
147 | #--------------------------------------------------------------------------- | |
148 |
# ' |
|
148 | # 'StdInSocketChannel' interface | |
149 | #--------------------------------------------------------------------------- |
|
149 | #--------------------------------------------------------------------------- | |
150 |
|
150 | |||
151 | def call_handlers(self, msg): |
|
151 | def call_handlers(self, msg): | |
@@ -190,8 +190,8 b' class QtKernelManager(KernelManager, SuperQObject):' | |||||
190 |
|
190 | |||
191 | # Use Qt-specific channel classes that emit signals. |
|
191 | # Use Qt-specific channel classes that emit signals. | |
192 | sub_channel_class = Type(QtSubSocketChannel) |
|
192 | sub_channel_class = Type(QtSubSocketChannel) | |
193 |
|
|
193 | shell_channel_class = Type(QtShellSocketChannel) | |
194 |
|
|
194 | stdin_channel_class = Type(QtStdInSocketChannel) | |
195 | hb_channel_class = Type(QtHBSocketChannel) |
|
195 | hb_channel_class = Type(QtHBSocketChannel) | |
196 |
|
196 | |||
197 | #--------------------------------------------------------------------------- |
|
197 | #--------------------------------------------------------------------------- | |
@@ -203,8 +203,8 b' class QtKernelManager(KernelManager, SuperQObject):' | |||||
203 | def start_kernel(self, *args, **kw): |
|
203 | def start_kernel(self, *args, **kw): | |
204 | """ Reimplemented for proper heartbeat management. |
|
204 | """ Reimplemented for proper heartbeat management. | |
205 | """ |
|
205 | """ | |
206 |
if self._ |
|
206 | if self._shell_channel is not None: | |
207 |
self._ |
|
207 | self._shell_channel.reset_first_reply() | |
208 | super(QtKernelManager, self).start_kernel(*args, **kw) |
|
208 | super(QtKernelManager, self).start_kernel(*args, **kw) | |
209 |
|
209 | |||
210 | #------ Channel management ------------------------------------------------- |
|
210 | #------ Channel management ------------------------------------------------- | |
@@ -222,13 +222,13 b' class QtKernelManager(KernelManager, SuperQObject):' | |||||
222 | self.stopped_channels.emit() |
|
222 | self.stopped_channels.emit() | |
223 |
|
223 | |||
224 | @property |
|
224 | @property | |
225 |
def |
|
225 | def shell_channel(self): | |
226 | """ Reimplemented for proper heartbeat management. |
|
226 | """ Reimplemented for proper heartbeat management. | |
227 | """ |
|
227 | """ | |
228 |
if self._ |
|
228 | if self._shell_channel is None: | |
229 |
self._ |
|
229 | self._shell_channel = super(QtKernelManager, self).shell_channel | |
230 |
self._ |
|
230 | self._shell_channel.first_reply.connect(self._first_reply) | |
231 |
return self._ |
|
231 | return self._shell_channel | |
232 |
|
232 | |||
233 | #--------------------------------------------------------------------------- |
|
233 | #--------------------------------------------------------------------------- | |
234 | # Protected interface |
|
234 | # Protected interface |
@@ -21,8 +21,8 b' from Queue import Queue, Empty' | |||||
21 | from IPython.utils import io |
|
21 | from IPython.utils import io | |
22 | from IPython.utils.traitlets import Type |
|
22 | from IPython.utils.traitlets import Type | |
23 |
|
23 | |||
24 | from .kernelmanager import (KernelManager, SubSocketChannel, |
|
24 | from .kernelmanager import (KernelManager, SubSocketChannel, HBSocketChannel, | |
25 |
|
|
25 | ShellSocketChannel, StdInSocketChannel) | |
26 |
|
26 | |||
27 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
28 | # Functions and classes |
|
28 | # Functions and classes | |
@@ -61,15 +61,15 b' class BlockingSubSocketChannel(SubSocketChannel):' | |||||
61 | return msgs |
|
61 | return msgs | |
62 |
|
62 | |||
63 |
|
63 | |||
64 |
class Blocking |
|
64 | class BlockingShellSocketChannel(ShellSocketChannel): | |
65 |
|
65 | |||
66 | def __init__(self, context, session, address=None): |
|
66 | def __init__(self, context, session, address=None): | |
67 |
super(Blocking |
|
67 | super(BlockingShellSocketChannel, self).__init__(context, session, | |
68 | address) |
|
68 | address) | |
69 | self._in_queue = Queue() |
|
69 | self._in_queue = Queue() | |
70 |
|
70 | |||
71 | def call_handlers(self, msg): |
|
71 | def call_handlers(self, msg): | |
72 |
#io.rprint('[[ |
|
72 | #io.rprint('[[Shell]]', msg) # dbg | |
73 | self._in_queue.put(msg) |
|
73 | self._in_queue.put(msg) | |
74 |
|
74 | |||
75 | def msg_ready(self): |
|
75 | def msg_ready(self): | |
@@ -94,7 +94,7 b' class BlockingXReqSocketChannel(XReqSocketChannel):' | |||||
94 | return msgs |
|
94 | return msgs | |
95 |
|
95 | |||
96 |
|
96 | |||
97 |
class Blocking |
|
97 | class BlockingStdInSocketChannel(StdInSocketChannel): | |
98 |
|
98 | |||
99 | def call_handlers(self, msg): |
|
99 | def call_handlers(self, msg): | |
100 | #io.rprint('[[Rep]]', msg) # dbg |
|
100 | #io.rprint('[[Rep]]', msg) # dbg | |
@@ -114,8 +114,8 b' class BlockingHBSocketChannel(HBSocketChannel):' | |||||
114 | class BlockingKernelManager(KernelManager): |
|
114 | class BlockingKernelManager(KernelManager): | |
115 |
|
115 | |||
116 | # The classes to use for the various channels. |
|
116 | # The classes to use for the various channels. | |
117 |
|
|
117 | shell_channel_class = Type(BlockingShellSocketChannel) | |
118 | sub_channel_class = Type(BlockingSubSocketChannel) |
|
118 | sub_channel_class = Type(BlockingSubSocketChannel) | |
119 |
|
|
119 | stdin_channel_class = Type(BlockingStdInSocketChannel) | |
120 | hb_channel_class = Type(BlockingHBSocketChannel) |
|
120 | hb_channel_class = Type(BlockingHBSocketChannel) | |
121 |
|
121 |
@@ -77,7 +77,7 b' def validate_string_dict(dct):' | |||||
77 | # ZMQ Socket Channel classes |
|
77 | # ZMQ Socket Channel classes | |
78 | #----------------------------------------------------------------------------- |
|
78 | #----------------------------------------------------------------------------- | |
79 |
|
79 | |||
80 |
class Z |
|
80 | class ZMQSocketChannel(Thread): | |
81 | """The base class for the channels that use ZMQ sockets. |
|
81 | """The base class for the channels that use ZMQ sockets. | |
82 | """ |
|
82 | """ | |
83 | context = None |
|
83 | context = None | |
@@ -99,7 +99,7 b' class ZmqSocketChannel(Thread):' | |||||
99 | address : tuple |
|
99 | address : tuple | |
100 | Standard (ip, port) tuple that the kernel is listening on. |
|
100 | Standard (ip, port) tuple that the kernel is listening on. | |
101 | """ |
|
101 | """ | |
102 |
super(Z |
|
102 | super(ZMQSocketChannel, self).__init__() | |
103 | self.daemon = True |
|
103 | self.daemon = True | |
104 |
|
104 | |||
105 | self.context = context |
|
105 | self.context = context | |
@@ -173,14 +173,14 b' class ZmqSocketChannel(Thread):' | |||||
173 | self.ioloop.add_callback(drop_io_state_callback) |
|
173 | self.ioloop.add_callback(drop_io_state_callback) | |
174 |
|
174 | |||
175 |
|
175 | |||
176 |
class |
|
176 | class ShellSocketChannel(ZMQSocketChannel): | |
177 | """The XREQ channel for issues request/replies to the kernel. |
|
177 | """The XREQ channel for issues request/replies to the kernel. | |
178 | """ |
|
178 | """ | |
179 |
|
179 | |||
180 | command_queue = None |
|
180 | command_queue = None | |
181 |
|
181 | |||
182 | def __init__(self, context, session, address): |
|
182 | def __init__(self, context, session, address): | |
183 |
super( |
|
183 | super(ShellSocketChannel, self).__init__(context, session, address) | |
184 | self.command_queue = Queue() |
|
184 | self.command_queue = Queue() | |
185 | self.ioloop = ioloop.IOLoop() |
|
185 | self.ioloop = ioloop.IOLoop() | |
186 |
|
186 | |||
@@ -196,7 +196,7 b' class XReqSocketChannel(ZmqSocketChannel):' | |||||
196 |
|
196 | |||
197 | def stop(self): |
|
197 | def stop(self): | |
198 | self.ioloop.stop() |
|
198 | self.ioloop.stop() | |
199 |
super( |
|
199 | super(ShellSocketChannel, self).stop() | |
200 |
|
200 | |||
201 | def call_handlers(self, msg): |
|
201 | def call_handlers(self, msg): | |
202 | """This method is called in the ioloop thread when a message arrives. |
|
202 | """This method is called in the ioloop thread when a message arrives. | |
@@ -382,7 +382,7 b' class XReqSocketChannel(ZmqSocketChannel):' | |||||
382 | self.add_io_state(POLLOUT) |
|
382 | self.add_io_state(POLLOUT) | |
383 |
|
383 | |||
384 |
|
384 | |||
385 |
class SubSocketChannel(Z |
|
385 | class SubSocketChannel(ZMQSocketChannel): | |
386 | """The SUB channel which listens for messages that the kernel publishes. |
|
386 | """The SUB channel which listens for messages that the kernel publishes. | |
387 | """ |
|
387 | """ | |
388 |
|
388 | |||
@@ -469,13 +469,13 b' class SubSocketChannel(ZmqSocketChannel):' | |||||
469 | self._flushed = True |
|
469 | self._flushed = True | |
470 |
|
470 | |||
471 |
|
471 | |||
472 |
class |
|
472 | class StdInSocketChannel(ZMQSocketChannel): | |
473 | """A reply channel to handle raw_input requests that the kernel makes.""" |
|
473 | """A reply channel to handle raw_input requests that the kernel makes.""" | |
474 |
|
474 | |||
475 | msg_queue = None |
|
475 | msg_queue = None | |
476 |
|
476 | |||
477 | def __init__(self, context, session, address): |
|
477 | def __init__(self, context, session, address): | |
478 |
super( |
|
478 | super(StdInSocketChannel, self).__init__(context, session, address) | |
479 | self.ioloop = ioloop.IOLoop() |
|
479 | self.ioloop = ioloop.IOLoop() | |
480 | self.msg_queue = Queue() |
|
480 | self.msg_queue = Queue() | |
481 |
|
481 | |||
@@ -491,7 +491,7 b' class RepSocketChannel(ZmqSocketChannel):' | |||||
491 |
|
491 | |||
492 | def stop(self): |
|
492 | def stop(self): | |
493 | self.ioloop.stop() |
|
493 | self.ioloop.stop() | |
494 |
super( |
|
494 | super(StdInSocketChannel, self).stop() | |
495 |
|
495 | |||
496 | def call_handlers(self, msg): |
|
496 | def call_handlers(self, msg): | |
497 | """This method is called in the ioloop thread when a message arrives. |
|
497 | """This method is called in the ioloop thread when a message arrives. | |
@@ -540,7 +540,7 b' class RepSocketChannel(ZmqSocketChannel):' | |||||
540 | self.add_io_state(POLLOUT) |
|
540 | self.add_io_state(POLLOUT) | |
541 |
|
541 | |||
542 |
|
542 | |||
543 |
class HBSocketChannel(Z |
|
543 | class HBSocketChannel(ZMQSocketChannel): | |
544 | """The heartbeat channel which monitors the kernel heartbeat. |
|
544 | """The heartbeat channel which monitors the kernel heartbeat. | |
545 |
|
545 | |||
546 | Note that the heartbeat channel is paused by default. As long as you start |
|
546 | Note that the heartbeat channel is paused by default. As long as you start | |
@@ -686,22 +686,22 b' class KernelManager(HasTraits):' | |||||
686 | kernel = Instance(Popen) |
|
686 | kernel = Instance(Popen) | |
687 |
|
687 | |||
688 | # The addresses for the communication channels. |
|
688 | # The addresses for the communication channels. | |
689 |
|
|
689 | shell_address = TCPAddress((LOCALHOST, 0)) | |
690 | sub_address = TCPAddress((LOCALHOST, 0)) |
|
690 | sub_address = TCPAddress((LOCALHOST, 0)) | |
691 |
|
|
691 | stdin_address = TCPAddress((LOCALHOST, 0)) | |
692 | hb_address = TCPAddress((LOCALHOST, 0)) |
|
692 | hb_address = TCPAddress((LOCALHOST, 0)) | |
693 |
|
693 | |||
694 | # The classes to use for the various channels. |
|
694 | # The classes to use for the various channels. | |
695 |
|
|
695 | shell_channel_class = Type(ShellSocketChannel) | |
696 | sub_channel_class = Type(SubSocketChannel) |
|
696 | sub_channel_class = Type(SubSocketChannel) | |
697 |
|
|
697 | stdin_channel_class = Type(StdInSocketChannel) | |
698 | hb_channel_class = Type(HBSocketChannel) |
|
698 | hb_channel_class = Type(HBSocketChannel) | |
699 |
|
699 | |||
700 | # Protected traits. |
|
700 | # Protected traits. | |
701 | _launch_args = Any |
|
701 | _launch_args = Any | |
702 |
_ |
|
702 | _shell_channel = Any | |
703 | _sub_channel = Any |
|
703 | _sub_channel = Any | |
704 |
_ |
|
704 | _stdin_channel = Any | |
705 | _hb_channel = Any |
|
705 | _hb_channel = Any | |
706 |
|
706 | |||
707 | def __init__(self, **kwargs): |
|
707 | def __init__(self, **kwargs): | |
@@ -713,7 +713,7 b' class KernelManager(HasTraits):' | |||||
713 | # Channel management methods: |
|
713 | # Channel management methods: | |
714 | #-------------------------------------------------------------------------- |
|
714 | #-------------------------------------------------------------------------- | |
715 |
|
715 | |||
716 |
def start_channels(self, |
|
716 | def start_channels(self, shell=True, sub=True, stdin=True, hb=True): | |
717 | """Starts the channels for this kernel. |
|
717 | """Starts the channels for this kernel. | |
718 |
|
718 | |||
719 | This will create the channels if they do not exist and then start |
|
719 | This will create the channels if they do not exist and then start | |
@@ -721,32 +721,32 b' class KernelManager(HasTraits):' | |||||
721 | must first call :method:`start_kernel`. If the channels have been |
|
721 | must first call :method:`start_kernel`. If the channels have been | |
722 | stopped and you call this, :class:`RuntimeError` will be raised. |
|
722 | stopped and you call this, :class:`RuntimeError` will be raised. | |
723 | """ |
|
723 | """ | |
724 |
if |
|
724 | if shell: | |
725 |
self. |
|
725 | self.shell_channel.start() | |
726 | if sub: |
|
726 | if sub: | |
727 | self.sub_channel.start() |
|
727 | self.sub_channel.start() | |
728 |
if |
|
728 | if stdin: | |
729 |
self. |
|
729 | self.stdin_channel.start() | |
730 | if hb: |
|
730 | if hb: | |
731 | self.hb_channel.start() |
|
731 | self.hb_channel.start() | |
732 |
|
732 | |||
733 | def stop_channels(self): |
|
733 | def stop_channels(self): | |
734 | """Stops all the running channels for this kernel. |
|
734 | """Stops all the running channels for this kernel. | |
735 | """ |
|
735 | """ | |
736 |
if self. |
|
736 | if self.shell_channel.is_alive(): | |
737 |
self. |
|
737 | self.shell_channel.stop() | |
738 | if self.sub_channel.is_alive(): |
|
738 | if self.sub_channel.is_alive(): | |
739 | self.sub_channel.stop() |
|
739 | self.sub_channel.stop() | |
740 |
if self. |
|
740 | if self.stdin_channel.is_alive(): | |
741 |
self. |
|
741 | self.stdin_channel.stop() | |
742 | if self.hb_channel.is_alive(): |
|
742 | if self.hb_channel.is_alive(): | |
743 | self.hb_channel.stop() |
|
743 | self.hb_channel.stop() | |
744 |
|
744 | |||
745 | @property |
|
745 | @property | |
746 | def channels_running(self): |
|
746 | def channels_running(self): | |
747 | """Are any of the channels created and running?""" |
|
747 | """Are any of the channels created and running?""" | |
748 |
return (self. |
|
748 | return (self.shell_channel.is_alive() or self.sub_channel.is_alive() or | |
749 |
self. |
|
749 | self.stdin_channel.is_alive() or self.hb_channel.is_alive()) | |
750 |
|
750 | |||
751 | #-------------------------------------------------------------------------- |
|
751 | #-------------------------------------------------------------------------- | |
752 | # Kernel process management methods: |
|
752 | # Kernel process management methods: | |
@@ -766,10 +766,10 b' class KernelManager(HasTraits):' | |||||
766 | **kw : optional |
|
766 | **kw : optional | |
767 | See respective options for IPython and Python kernels. |
|
767 | See respective options for IPython and Python kernels. | |
768 | """ |
|
768 | """ | |
769 |
|
|
769 | shell, sub, stdin, hb = self.shell_address, self.sub_address, \ | |
770 |
self. |
|
770 | self.stdin_address, self.hb_address | |
771 |
if |
|
771 | if shell[0] not in LOCAL_IPS or sub[0] not in LOCAL_IPS or \ | |
772 |
|
|
772 | stdin[0] not in LOCAL_IPS or hb[0] not in LOCAL_IPS: | |
773 | raise RuntimeError("Can only launch a kernel on a local interface. " |
|
773 | raise RuntimeError("Can only launch a kernel on a local interface. " | |
774 | "Make sure that the '*_address' attributes are " |
|
774 | "Make sure that the '*_address' attributes are " | |
775 | "configured properly. " |
|
775 | "configured properly. " | |
@@ -782,11 +782,11 b' class KernelManager(HasTraits):' | |||||
782 | else: |
|
782 | else: | |
783 | from pykernel import launch_kernel |
|
783 | from pykernel import launch_kernel | |
784 | self.kernel, xrep, pub, req, _hb = launch_kernel( |
|
784 | self.kernel, xrep, pub, req, _hb = launch_kernel( | |
785 |
shell_port= |
|
785 | shell_port=shell[1], iopub_port=sub[1], | |
786 |
stdin_port= |
|
786 | stdin_port=stdin[1], hb_port=hb[1], **kw) | |
787 |
self. |
|
787 | self.shell_address = (shell[0], xrep) | |
788 | self.sub_address = (sub[0], pub) |
|
788 | self.sub_address = (sub[0], pub) | |
789 |
self. |
|
789 | self.stdin_address = (stdin[0], req) | |
790 | self.hb_address = (hb[0], _hb) |
|
790 | self.hb_address = (hb[0], _hb) | |
791 |
|
791 | |||
792 | def shutdown_kernel(self, restart=False): |
|
792 | def shutdown_kernel(self, restart=False): | |
@@ -805,7 +805,7 b' class KernelManager(HasTraits):' | |||||
805 | # Don't send any additional kernel kill messages immediately, to give |
|
805 | # Don't send any additional kernel kill messages immediately, to give | |
806 | # the kernel a chance to properly execute shutdown actions. Wait for at |
|
806 | # the kernel a chance to properly execute shutdown actions. Wait for at | |
807 | # most 1s, checking every 0.1s. |
|
807 | # most 1s, checking every 0.1s. | |
808 |
self. |
|
808 | self.shell_channel.shutdown(restart=restart) | |
809 | for i in range(10): |
|
809 | for i in range(10): | |
810 | if self.is_alive: |
|
810 | if self.is_alive: | |
811 | time.sleep(0.1) |
|
811 | time.sleep(0.1) | |
@@ -931,13 +931,13 b' class KernelManager(HasTraits):' | |||||
931 | #-------------------------------------------------------------------------- |
|
931 | #-------------------------------------------------------------------------- | |
932 |
|
932 | |||
933 | @property |
|
933 | @property | |
934 |
def |
|
934 | def shell_channel(self): | |
935 | """Get the REQ socket channel object to make requests of the kernel.""" |
|
935 | """Get the REQ socket channel object to make requests of the kernel.""" | |
936 |
if self._ |
|
936 | if self._shell_channel is None: | |
937 |
self._ |
|
937 | self._shell_channel = self.shell_channel_class(self.context, | |
938 | self.session, |
|
938 | self.session, | |
939 |
self. |
|
939 | self.shell_address) | |
940 |
return self._ |
|
940 | return self._shell_channel | |
941 |
|
941 | |||
942 | @property |
|
942 | @property | |
943 | def sub_channel(self): |
|
943 | def sub_channel(self): | |
@@ -949,13 +949,13 b' class KernelManager(HasTraits):' | |||||
949 | return self._sub_channel |
|
949 | return self._sub_channel | |
950 |
|
950 | |||
951 | @property |
|
951 | @property | |
952 |
def |
|
952 | def stdin_channel(self): | |
953 | """Get the REP socket channel object to handle stdin (raw_input).""" |
|
953 | """Get the REP socket channel object to handle stdin (raw_input).""" | |
954 |
if self._ |
|
954 | if self._stdin_channel is None: | |
955 |
self._ |
|
955 | self._stdin_channel = self.stdin_channel_class(self.context, | |
956 | self.session, |
|
956 | self.session, | |
957 |
self. |
|
957 | self.stdin_address) | |
958 |
return self._ |
|
958 | return self._stdin_channel | |
959 |
|
959 | |||
960 | @property |
|
960 | @property | |
961 | def hb_channel(self): |
|
961 | def hb_channel(self): |
General Comments 0
You need to be logged in to leave comments.
Login now