diff --git a/IPython/kernel/manager.py b/IPython/kernel/manager.py index 75f7345..f86d353 100644 --- a/IPython/kernel/manager.py +++ b/IPython/kernel/manager.py @@ -117,36 +117,38 @@ class KernelManager(LoggingConfigurable, ConnectionFileMixin): else: return "%s://%s-%s" % (transport, ip, port) - def _create_connected_socket(self, channel): + def _create_connected_socket(self, channel, identity=None): """Create a zmq Socket and connect it to the kernel.""" url = self._make_url(channel) socket_type = _socket_types[channel] - sock = self.context.socket(socket_type) self.log.info("Connecting to: %s" % url) + sock = self.context.socket(socket_type) + if identity: + sock.identity = identity sock.connect(url) return sock - def connect_iopub(self): + def connect_iopub(self, identity=None): """return zmq Socket connected to the IOPub channel""" - sock = self._create_connected_socket('iopub') + sock = self._create_connected_socket('iopub', identity=identity) sock.setsockopt(zmq.SUBSCRIBE, b'') return sock - def connect_shell(self): + def connect_shell(self, identity=None): """return zmq Socket connected to the Shell channel""" - return self._create_connected_socket('shell') + return self._create_connected_socket('shell', identity=identity) - def connect_stdin(self): + def connect_stdin(self, identity=None): """return zmq Socket connected to the StdIn channel""" - return self._create_connected_socket('stdin') + return self._create_connected_socket('stdin', identity=identity) - def connect_hb(self): + def connect_hb(self, identity=None): """return zmq Socket connected to the Heartbeat channel""" - return self._create_connected_socket('hb') + return self._create_connected_socket('hb', identity=identity) - def connect_control(self): + def connect_control(self, identity=None): """return zmq Socket connected to the Heartbeat channel""" - return self._create_connected_socket('control') + return self._create_connected_socket('control', identity=identity) #-------------------------------------------------------------------------- # Kernel management diff --git a/IPython/kernel/multikernelmanager.py b/IPython/kernel/multikernelmanager.py index 1483416..7cd9988 100644 --- a/IPython/kernel/multikernelmanager.py +++ b/IPython/kernel/multikernelmanager.py @@ -219,13 +219,15 @@ class MultiKernelManager(LoggingConfigurable): """ @kernel_method - def connect_iopub(self, kernel_id): + def connect_iopub(self, kernel_id, identity=None): """Return a zmq Socket connected to the iopub channel. Parameters ========== kernel_id : uuid - The id of the kernel. + The id of the kernel + identity : bytes (optional) + The zmq identity of the socket Returns ======= @@ -233,13 +235,15 @@ class MultiKernelManager(LoggingConfigurable): """ @kernel_method - def connect_shell(self, kernel_id): + def connect_shell(self, kernel_id, identity=None): """Return a zmq Socket connected to the shell channel. Parameters ========== kernel_id : uuid - The id of the kernel. + The id of the kernel + identity : bytes (optional) + The zmq identity of the socket Returns ======= @@ -247,13 +251,15 @@ class MultiKernelManager(LoggingConfigurable): """ @kernel_method - def connect_stdin(self, kernel_id): + def connect_stdin(self, kernel_id, identity=None): """Return a zmq Socket connected to the stdin channel. Parameters ========== kernel_id : uuid - The id of the kernel. + The id of the kernel + identity : bytes (optional) + The zmq identity of the socket Returns ======= @@ -261,13 +267,15 @@ class MultiKernelManager(LoggingConfigurable): """ @kernel_method - def connect_hb(self, kernel_id): + def connect_hb(self, kernel_id, identity=None): """Return a zmq Socket connected to the hb channel. Parameters ========== kernel_id : uuid - The id of the kernel. + The id of the kernel + identity : bytes (optional) + The zmq identity of the socket Returns =======