Browse files

cleanup channel names to match function not socket

closes gh-178
  • Loading branch information...
1 parent a3fc5dc commit 7940e2fd73db1fde65596faf6032ae2d46ace2a5 @minrk committed Jun 1, 2011
View
8 IPython/frontend/qt/base_frontend_mixin.py
@@ -30,8 +30,8 @@ def _set_kernel_manager(self, kernel_manager):
# Disconnect the old kernel manager's channels.
old_manager.sub_channel.message_received.disconnect(self._dispatch)
- old_manager.xreq_channel.message_received.disconnect(self._dispatch)
- old_manager.rep_channel.message_received.disconnect(self._dispatch)
+ old_manager.shell_channel.message_received.disconnect(self._dispatch)
+ old_manager.stdin_channel.message_received.disconnect(self._dispatch)
old_manager.hb_channel.kernel_died.disconnect(
self._handle_kernel_died)
@@ -50,8 +50,8 @@ def _set_kernel_manager(self, kernel_manager):
# Connect the new kernel manager's channels.
kernel_manager.sub_channel.message_received.connect(self._dispatch)
- kernel_manager.xreq_channel.message_received.connect(self._dispatch)
- kernel_manager.rep_channel.message_received.connect(self._dispatch)
+ kernel_manager.shell_channel.message_received.connect(self._dispatch)
+ kernel_manager.stdin_channel.message_received.connect(self._dispatch)
kernel_manager.hb_channel.kernel_died.connect(self._handle_kernel_died)
# Handle the case where the kernel manager started channels before
View
8 IPython/frontend/qt/console/frontend_widget.py
@@ -184,7 +184,7 @@ def _execute(self, source, hidden):
See parent class :meth:`execute` docstring for full details.
"""
- msg_id = self.kernel_manager.xreq_channel.execute(source, hidden)
+ msg_id = self.kernel_manager.shell_channel.execute(source, hidden)
self._request_info['execute'] = self._ExecutionRequest(msg_id, 'user')
self._hidden = hidden
if not hidden:
@@ -330,7 +330,7 @@ def _handle_input_request(self, msg):
self.kernel_manager.sub_channel.flush()
def callback(line):
- self.kernel_manager.rep_channel.input(line)
+ self.kernel_manager.stdin_channel.input(line)
self._readline(msg['content']['prompt'], callback=callback)
def _handle_kernel_died(self, since_last_heartbeat):
@@ -518,7 +518,7 @@ def _call_tip(self):
# Send the metadata request to the kernel
name = '.'.join(context)
- msg_id = self.kernel_manager.xreq_channel.object_info(name)
+ msg_id = self.kernel_manager.shell_channel.object_info(name)
pos = self._get_cursor().position()
self._request_info['call_tip'] = self._CallTipRequest(msg_id, pos)
return True
@@ -529,7 +529,7 @@ def _complete(self):
context = self._get_context()
if context:
# Send the completion request to the kernel
- msg_id = self.kernel_manager.xreq_channel.complete(
+ msg_id = self.kernel_manager.shell_channel.complete(
'.'.join(context), # text
self._get_input_buffer_cursor_line(), # line
self._get_input_buffer_cursor_column(), # cursor_pos
View
6 IPython/frontend/qt/console/ipython_widget.py
@@ -222,7 +222,7 @@ def _started_channels(self):
""" Reimplemented to make a history request.
"""
super(IPythonWidget, self)._started_channels()
- self.kernel_manager.xreq_channel.history(hist_access_type='tail', n=1000)
+ self.kernel_manager.shell_channel.history(hist_access_type='tail', n=1000)
#---------------------------------------------------------------------------
# 'ConsoleWidget' public interface
@@ -264,7 +264,7 @@ def _complete(self):
text = ''
# Send the completion request to the kernel
- msg_id = self.kernel_manager.xreq_channel.complete(
+ msg_id = self.kernel_manager.shell_channel.complete(
text, # text
self._get_input_buffer_cursor_line(), # line
self._get_input_buffer_cursor_column(), # cursor_pos
@@ -315,7 +315,7 @@ def _show_interpreter_prompt(self, number=None):
"""
# If a number was not specified, make a prompt number request.
if number is None:
- msg_id = self.kernel_manager.xreq_channel.execute('', silent=True)
+ msg_id = self.kernel_manager.shell_channel.execute('', silent=True)
info = self._ExecutionRequest(msg_id, 'prompt')
self._request_info['execute'] = info
return
View
4 IPython/frontend/qt/console/ipythonqt.py
@@ -257,9 +257,9 @@ def init_kernel_manager(self):
# Create a KernelManager and start a kernel.
self.kernel_manager = QtKernelManager(
- xreq_address=(self.ip, self.shell_port),
+ shell_address=(self.ip, self.shell_port),
sub_address=(self.ip, self.iopub_port),
- rep_address=(self.ip, self.stdin_port),
+ stdin_address=(self.ip, self.stdin_port),
hb_address=(self.ip, self.hb_port)
)
# start the kernel
View
32 IPython/frontend/qt/kernelmanager.py
@@ -7,7 +7,7 @@
# IPython imports.
from IPython.utils.traitlets import Type
from IPython.zmq.kernelmanager import KernelManager, SubSocketChannel, \
- XReqSocketChannel, RepSocketChannel, HBSocketChannel
+ ShellSocketChannel, StdInSocketChannel, HBSocketChannel
from util import MetaQObjectHasTraits, SuperQObject
@@ -20,7 +20,7 @@ class SocketChannelQObject(SuperQObject):
stopped = QtCore.Signal()
#---------------------------------------------------------------------------
- # 'ZmqSocketChannel' interface
+ # 'ZMQSocketChannel' interface
#---------------------------------------------------------------------------
def start(self):
@@ -36,7 +36,7 @@ def stop(self):
self.stopped.emit()
-class QtXReqSocketChannel(SocketChannelQObject, XReqSocketChannel):
+class QtShellSocketChannel(SocketChannelQObject, ShellSocketChannel):
# Emitted when any message is received.
message_received = QtCore.Signal(object)
@@ -56,7 +56,7 @@ class QtXReqSocketChannel(SocketChannelQObject, XReqSocketChannel):
_handlers_called = False
#---------------------------------------------------------------------------
- # 'XReqSocketChannel' interface
+ # 'ShellSocketChannel' interface
#---------------------------------------------------------------------------
def call_handlers(self, msg):
@@ -76,7 +76,7 @@ def call_handlers(self, msg):
self._handlers_called = True
#---------------------------------------------------------------------------
- # 'QtXReqSocketChannel' interface
+ # 'QtShellSocketChannel' interface
#---------------------------------------------------------------------------
def reset_first_reply(self):
@@ -136,7 +136,7 @@ def flush(self):
QtCore.QCoreApplication.instance().processEvents()
-class QtRepSocketChannel(SocketChannelQObject, RepSocketChannel):
+class QtStdInSocketChannel(SocketChannelQObject, StdInSocketChannel):
# Emitted when any message is received.
message_received = QtCore.Signal(object)
@@ -145,7 +145,7 @@ class QtRepSocketChannel(SocketChannelQObject, RepSocketChannel):
input_requested = QtCore.Signal(object)
#---------------------------------------------------------------------------
- # 'RepSocketChannel' interface
+ # 'StdInSocketChannel' interface
#---------------------------------------------------------------------------
def call_handlers(self, msg):
@@ -190,8 +190,8 @@ class QtKernelManager(KernelManager, SuperQObject):
# Use Qt-specific channel classes that emit signals.
sub_channel_class = Type(QtSubSocketChannel)
- xreq_channel_class = Type(QtXReqSocketChannel)
- rep_channel_class = Type(QtRepSocketChannel)
+ shell_channel_class = Type(QtShellSocketChannel)
+ stdin_channel_class = Type(QtStdInSocketChannel)
hb_channel_class = Type(QtHBSocketChannel)
#---------------------------------------------------------------------------
@@ -203,8 +203,8 @@ class QtKernelManager(KernelManager, SuperQObject):
def start_kernel(self, *args, **kw):
""" Reimplemented for proper heartbeat management.
"""
- if self._xreq_channel is not None:
- self._xreq_channel.reset_first_reply()
+ if self._shell_channel is not None:
+ self._shell_channel.reset_first_reply()
super(QtKernelManager, self).start_kernel(*args, **kw)
#------ Channel management -------------------------------------------------
@@ -222,13 +222,13 @@ def stop_channels(self):
self.stopped_channels.emit()
@property
- def xreq_channel(self):
+ def shell_channel(self):
""" Reimplemented for proper heartbeat management.
"""
- if self._xreq_channel is None:
- self._xreq_channel = super(QtKernelManager, self).xreq_channel
- self._xreq_channel.first_reply.connect(self._first_reply)
- return self._xreq_channel
+ if self._shell_channel is None:
+ self._shell_channel = super(QtKernelManager, self).shell_channel
+ self._shell_channel.first_reply.connect(self._first_reply)
+ return self._shell_channel
#---------------------------------------------------------------------------
# Protected interface
View
16 IPython/zmq/blockingkernelmanager.py
@@ -21,8 +21,8 @@
from IPython.utils import io
from IPython.utils.traitlets import Type
-from .kernelmanager import (KernelManager, SubSocketChannel,
- XReqSocketChannel, RepSocketChannel, HBSocketChannel)
+from .kernelmanager import (KernelManager, SubSocketChannel, HBSocketChannel,
+ ShellSocketChannel, StdInSocketChannel)
#-----------------------------------------------------------------------------
# Functions and classes
@@ -61,15 +61,15 @@ def get_msgs(self):
return msgs
-class BlockingXReqSocketChannel(XReqSocketChannel):
+class BlockingShellSocketChannel(ShellSocketChannel):
def __init__(self, context, session, address=None):
- super(BlockingXReqSocketChannel, self).__init__(context, session,
+ super(BlockingShellSocketChannel, self).__init__(context, session,
address)
self._in_queue = Queue()
def call_handlers(self, msg):
- #io.rprint('[[XReq]]', msg) # dbg
+ #io.rprint('[[Shell]]', msg) # dbg
self._in_queue.put(msg)
def msg_ready(self):
@@ -94,7 +94,7 @@ def get_msgs(self):
return msgs
-class BlockingRepSocketChannel(RepSocketChannel):
+class BlockingStdInSocketChannel(StdInSocketChannel):
def call_handlers(self, msg):
#io.rprint('[[Rep]]', msg) # dbg
@@ -114,8 +114,8 @@ def call_handlers(self, since_last_heartbeat):
class BlockingKernelManager(KernelManager):
# The classes to use for the various channels.
- xreq_channel_class = Type(BlockingXReqSocketChannel)
+ shell_channel_class = Type(BlockingShellSocketChannel)
sub_channel_class = Type(BlockingSubSocketChannel)
- rep_channel_class = Type(BlockingRepSocketChannel)
+ stdin_channel_class = Type(BlockingStdInSocketChannel)
hb_channel_class = Type(BlockingHBSocketChannel)
View
92 IPython/zmq/kernelmanager.py
@@ -77,7 +77,7 @@ def validate_string_dict(dct):
# ZMQ Socket Channel classes
#-----------------------------------------------------------------------------
-class ZmqSocketChannel(Thread):
+class ZMQSocketChannel(Thread):
"""The base class for the channels that use ZMQ sockets.
"""
context = None
@@ -99,7 +99,7 @@ def __init__(self, context, session, address):
address : tuple
Standard (ip, port) tuple that the kernel is listening on.
"""
- super(ZmqSocketChannel, self).__init__()
+ super(ZMQSocketChannel, self).__init__()
self.daemon = True
self.context = context
@@ -173,14 +173,14 @@ def drop_io_state_callback():
self.ioloop.add_callback(drop_io_state_callback)
-class XReqSocketChannel(ZmqSocketChannel):
+class ShellSocketChannel(ZMQSocketChannel):
"""The XREQ channel for issues request/replies to the kernel.
"""
command_queue = None
def __init__(self, context, session, address):
- super(XReqSocketChannel, self).__init__(context, session, address)
+ super(ShellSocketChannel, self).__init__(context, session, address)
self.command_queue = Queue()
self.ioloop = ioloop.IOLoop()
@@ -196,7 +196,7 @@ def run(self):
def stop(self):
self.ioloop.stop()
- super(XReqSocketChannel, self).stop()
+ super(ShellSocketChannel, self).stop()
def call_handlers(self, msg):
"""This method is called in the ioloop thread when a message arrives.
@@ -382,7 +382,7 @@ def _queue_request(self, msg):
self.add_io_state(POLLOUT)
-class SubSocketChannel(ZmqSocketChannel):
+class SubSocketChannel(ZMQSocketChannel):
"""The SUB channel which listens for messages that the kernel publishes.
"""
@@ -469,13 +469,13 @@ def _flush(self):
self._flushed = True
-class RepSocketChannel(ZmqSocketChannel):
+class StdInSocketChannel(ZMQSocketChannel):
"""A reply channel to handle raw_input requests that the kernel makes."""
msg_queue = None
def __init__(self, context, session, address):
- super(RepSocketChannel, self).__init__(context, session, address)
+ super(StdInSocketChannel, self).__init__(context, session, address)
self.ioloop = ioloop.IOLoop()
self.msg_queue = Queue()
@@ -491,7 +491,7 @@ def run(self):
def stop(self):
self.ioloop.stop()
- super(RepSocketChannel, self).stop()
+ super(StdInSocketChannel, self).stop()
def call_handlers(self, msg):
"""This method is called in the ioloop thread when a message arrives.
@@ -540,7 +540,7 @@ def _queue_reply(self, msg):
self.add_io_state(POLLOUT)
-class HBSocketChannel(ZmqSocketChannel):
+class HBSocketChannel(ZMQSocketChannel):
"""The heartbeat channel which monitors the kernel heartbeat.
Note that the heartbeat channel is paused by default. As long as you start
@@ -686,22 +686,22 @@ class KernelManager(HasTraits):
kernel = Instance(Popen)
# The addresses for the communication channels.
- xreq_address = TCPAddress((LOCALHOST, 0))
+ shell_address = TCPAddress((LOCALHOST, 0))
sub_address = TCPAddress((LOCALHOST, 0))
- rep_address = TCPAddress((LOCALHOST, 0))
+ stdin_address = TCPAddress((LOCALHOST, 0))
hb_address = TCPAddress((LOCALHOST, 0))
# The classes to use for the various channels.
- xreq_channel_class = Type(XReqSocketChannel)
+ shell_channel_class = Type(ShellSocketChannel)
sub_channel_class = Type(SubSocketChannel)
- rep_channel_class = Type(RepSocketChannel)
+ stdin_channel_class = Type(StdInSocketChannel)
hb_channel_class = Type(HBSocketChannel)
# Protected traits.
_launch_args = Any
- _xreq_channel = Any
+ _shell_channel = Any
_sub_channel = Any
- _rep_channel = Any
+ _stdin_channel = Any
_hb_channel = Any
def __init__(self, **kwargs):
@@ -713,40 +713,40 @@ def __init__(self, **kwargs):
# Channel management methods:
#--------------------------------------------------------------------------
- def start_channels(self, xreq=True, sub=True, rep=True, hb=True):
+ def start_channels(self, shell=True, sub=True, stdin=True, hb=True):
"""Starts the channels for this kernel.
This will create the channels if they do not exist and then start
them. If port numbers of 0 are being used (random ports) then you
must first call :method:`start_kernel`. If the channels have been
stopped and you call this, :class:`RuntimeError` will be raised.
"""
- if xreq:
- self.xreq_channel.start()
+ if shell:
+ self.shell_channel.start()
if sub:
self.sub_channel.start()
- if rep:
- self.rep_channel.start()
+ if stdin:
+ self.stdin_channel.start()
if hb:
self.hb_channel.start()
def stop_channels(self):
"""Stops all the running channels for this kernel.
"""
- if self.xreq_channel.is_alive():
- self.xreq_channel.stop()
+ if self.shell_channel.is_alive():
+ self.shell_channel.stop()
if self.sub_channel.is_alive():
self.sub_channel.stop()
- if self.rep_channel.is_alive():
- self.rep_channel.stop()
+ if self.stdin_channel.is_alive():
+ self.stdin_channel.stop()
if self.hb_channel.is_alive():
self.hb_channel.stop()
@property
def channels_running(self):
"""Are any of the channels created and running?"""
- return (self.xreq_channel.is_alive() or self.sub_channel.is_alive() or
- self.rep_channel.is_alive() or self.hb_channel.is_alive())
+ return (self.shell_channel.is_alive() or self.sub_channel.is_alive() or
+ self.stdin_channel.is_alive() or self.hb_channel.is_alive())
#--------------------------------------------------------------------------
# Kernel process management methods:
@@ -766,10 +766,10 @@ def start_kernel(self, **kw):
**kw : optional
See respective options for IPython and Python kernels.
"""
- xreq, sub, rep, hb = self.xreq_address, self.sub_address, \
- self.rep_address, self.hb_address
- if xreq[0] not in LOCAL_IPS or sub[0] not in LOCAL_IPS or \
- rep[0] not in LOCAL_IPS or hb[0] not in LOCAL_IPS:
+ shell, sub, stdin, hb = self.shell_address, self.sub_address, \
+ self.stdin_address, self.hb_address
+ if shell[0] not in LOCAL_IPS or sub[0] not in LOCAL_IPS or \
+ stdin[0] not in LOCAL_IPS or hb[0] not in LOCAL_IPS:
raise RuntimeError("Can only launch a kernel on a local interface. "
"Make sure that the '*_address' attributes are "
"configured properly. "
@@ -782,11 +782,11 @@ def start_kernel(self, **kw):
else:
from pykernel import launch_kernel
self.kernel, xrep, pub, req, _hb = launch_kernel(
- shell_port=xreq[1], iopub_port=sub[1],
- stdin_port=rep[1], hb_port=hb[1], **kw)
- self.xreq_address = (xreq[0], xrep)
+ shell_port=shell[1], iopub_port=sub[1],
+ stdin_port=stdin[1], hb_port=hb[1], **kw)
+ self.shell_address = (shell[0], xrep)
self.sub_address = (sub[0], pub)
- self.rep_address = (rep[0], req)
+ self.stdin_address = (stdin[0], req)
self.hb_address = (hb[0], _hb)
def shutdown_kernel(self, restart=False):
@@ -805,7 +805,7 @@ def shutdown_kernel(self, restart=False):
# Don't send any additional kernel kill messages immediately, to give
# the kernel a chance to properly execute shutdown actions. Wait for at
# most 1s, checking every 0.1s.
- self.xreq_channel.shutdown(restart=restart)
+ self.shell_channel.shutdown(restart=restart)
for i in range(10):
if self.is_alive:
time.sleep(0.1)
@@ -931,13 +931,13 @@ def is_alive(self):
#--------------------------------------------------------------------------
@property
- def xreq_channel(self):
+ def shell_channel(self):
"""Get the REQ socket channel object to make requests of the kernel."""
- if self._xreq_channel is None:
- self._xreq_channel = self.xreq_channel_class(self.context,
+ if self._shell_channel is None:
+ self._shell_channel = self.shell_channel_class(self.context,
self.session,
- self.xreq_address)
- return self._xreq_channel
+ self.shell_address)
+ return self._shell_channel
@property
def sub_channel(self):
@@ -949,13 +949,13 @@ def sub_channel(self):
return self._sub_channel
@property
- def rep_channel(self):
+ def stdin_channel(self):
"""Get the REP socket channel object to handle stdin (raw_input)."""
- if self._rep_channel is None:
- self._rep_channel = self.rep_channel_class(self.context,
+ if self._stdin_channel is None:
+ self._stdin_channel = self.stdin_channel_class(self.context,
self.session,
- self.rep_address)
- return self._rep_channel
+ self.stdin_address)
+ return self._stdin_channel
@property
def hb_channel(self):
View
4 IPython/zmq/tests/test_message_spec.py
@@ -35,6 +35,6 @@ def teardown():
# Actual tests
def test_execute():
- KM.xreq_channel.execute(code='x=1')
- KM.xreq_channel.execute(code='print 1')
+ KM.shell_channel.execute(code='x=1')
+ KM.shell_channel.execute(code='print 1')

0 comments on commit 7940e2f

Please sign in to comment.