##// END OF EJS Templates
New connect_request message type added.
Brian Granger -
Show More
@@ -97,7 +97,8 b' def make_kernel(namespace, kernel_factory,'
97
97
98 hb = Heartbeat(context, (namespace.ip, namespace.hb))
98 hb = Heartbeat(context, (namespace.ip, namespace.hb))
99 hb.start()
99 hb.start()
100 io.raw_print("Heartbeat REP Channel on port", hb.port)
100 hb_port = hb.port
101 io.raw_print("Heartbeat REP Channel on port", hb_port)
101
102
102 # Redirect input streams and set a display hook.
103 # Redirect input streams and set a display hook.
103 if out_stream_factory:
104 if out_stream_factory:
@@ -107,8 +108,11 b' def make_kernel(namespace, kernel_factory,'
107 sys.displayhook = display_hook_factory(session, pub_socket)
108 sys.displayhook = display_hook_factory(session, pub_socket)
108
109
109 # Create the kernel.
110 # Create the kernel.
110 return kernel_factory(session=session, reply_socket=reply_socket,
111 kernel = kernel_factory(session=session, reply_socket=reply_socket,
111 pub_socket=pub_socket, req_socket=req_socket)
112 pub_socket=pub_socket, req_socket=req_socket)
113 kernel.record_ports(xrep_port=xrep_port, pub_port=pub_port,
114 req_port=req_port, hb_port=hb_port)
115 return kernel
112
116
113
117
114 def start_kernel(namespace, kernel):
118 def start_kernel(namespace, kernel):
@@ -75,6 +75,10 b' class Kernel(Configurable):'
75 # the end of our shutdown process (which happens after the underlying
75 # the end of our shutdown process (which happens after the underlying
76 # IPython shell's own shutdown).
76 # IPython shell's own shutdown).
77 _shutdown_message = None
77 _shutdown_message = None
78
79 # This is a dict of port number that the kernel is listening on. It is set
80 # by record_ports and used by connect_request.
81 _recorded_ports = None
78
82
79 def __init__(self, **kwargs):
83 def __init__(self, **kwargs):
80 super(Kernel, self).__init__(**kwargs)
84 super(Kernel, self).__init__(**kwargs)
@@ -143,7 +147,20 b' class Kernel(Configurable):'
143 while True:
147 while True:
144 time.sleep(self._poll_interval)
148 time.sleep(self._poll_interval)
145 self.do_one_iteration()
149 self.do_one_iteration()
146
150
151 def record_ports(self, xrep_port, pub_port, req_port, hb_port):
152 """Record the ports that this kernel is using.
153
154 The creator of the Kernel instance must call this methods if they
155 want the :meth:`connect_request` method to return the port numbers.
156 """
157 self._recorded_ports = {
158 'xrep_port' : xreq_port,
159 'pub_port' : pub_port,
160 'req_port' : req_port,
161 'hb_port' : hb_port
162 }
163
147 #---------------------------------------------------------------------------
164 #---------------------------------------------------------------------------
148 # Kernel request handlers
165 # Kernel request handlers
149 #---------------------------------------------------------------------------
166 #---------------------------------------------------------------------------
@@ -287,12 +304,21 b' class Kernel(Configurable):'
287 msg = self.session.send(self.reply_socket, 'history_reply',
304 msg = self.session.send(self.reply_socket, 'history_reply',
288 content, parent, ident)
305 content, parent, ident)
289 io.raw_print(msg)
306 io.raw_print(msg)
290
307
308 def connect_request(self, ident, parent):
309 if self._recorded_ports is not None:
310 content = self._recorded_ports.copy()
311 else:
312 content = {}
313 msg = self.session.send(self.reply_socket, 'connect_reply',
314 content, parent, ident)
315 io.raw_print(msg)
316
291 def shutdown_request(self, ident, parent):
317 def shutdown_request(self, ident, parent):
292 self.shell.exit_now = True
318 self.shell.exit_now = True
293 self._shutdown_message = self.session.msg(u'shutdown_reply', {}, parent)
319 self._shutdown_message = self.session.msg(u'shutdown_reply', {}, parent)
294 sys.exit(0)
320 sys.exit(0)
295
321
296 #---------------------------------------------------------------------------
322 #---------------------------------------------------------------------------
297 # Protected interface
323 # Protected interface
298 #---------------------------------------------------------------------------
324 #---------------------------------------------------------------------------
@@ -536,6 +536,30 b' Message type: ``history_reply``::'
536 }
536 }
537
537
538
538
539 Connect
540 -------
541
542 When a client connects to the request/reply socket of the kernel, it can issue
543 a connect request to get basic information about the kernel, such as the ports
544 the other ZeroMQ sockets are listening on. This allows clients to only have
545 to know about a single port (the XREQ/XREP channel) to connect to a kernel.
546
547 Message type: ``connect_request``::
548
549 content = {
550 }
551
552 Message type: ``connect_reply``::
553
554 content = {
555 'xrep_port' : int # The port the XREP socket is listening on.
556 'pub_port' : int # The port the PUB socket is listening on.
557 'req_port' : int # The port the REQ socket is listening on.
558 'hb_port' : int # The port the heartbeat socket is listening on.
559 }
560
561
562
539 Kernel shutdown
563 Kernel shutdown
540 ---------------
564 ---------------
541
565
General Comments 0
You need to be logged in to leave comments. Login now