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