Skip to content

Commit

Permalink
Merge pull request ipython#2805 from minrk/fixnb
Browse files Browse the repository at this point in the history
fix KeyError creating ZMQStreams in notebook

typo in PR ipython#2775 prevented websocket connections from ever being established
  • Loading branch information
minrk committed Jan 18, 2013
2 parents c904de4 + 0d40a29 commit cc7c183
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions IPython/frontend/html/notebook/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ def _make_url(self, transport, ip, port):
else:
return "%s://%s-%s" % (transport, ip, port)

def _create_connected_stream(self, kernel_id, socket_type):
def _create_connected_stream(self, kernel_id, socket_type, channel):
"""Create a connected ZMQStream for a kernel."""
cinfo = self.get_connection_info(kernel_id)
url = self._make_url(cinfo['transport'], cinfo['ip'], cinfo['port'])
url = self._make_url(cinfo['transport'], cinfo['ip'],
cinfo['%s_port' % channel]
)
sock = self.context.socket(socket_type)
self.log.info("Connecting to: %s" % url)
sock.connect(url)
Expand All @@ -221,7 +223,7 @@ def create_iopub_stream(self, kernel_id):
=======
stream : ZMQStream
"""
iopub_stream = self._create_connected_stream(kernel_id, zmq.SUB)
iopub_stream = self._create_connected_stream(kernel_id, zmq.SUB, 'iopub')
iopub_stream.socket.setsockopt(zmq.SUBSCRIBE, b'')
return iopub_stream

Expand All @@ -237,7 +239,7 @@ def create_shell_stream(self, kernel_id):
=======
stream : ZMQStream
"""
shell_stream = self._create_connected_stream(kernel_id, zmq.DEALER)
shell_stream = self._create_connected_stream(kernel_id, zmq.DEALER, 'shell')
return shell_stream

def create_hb_stream(self, kernel_id):
Expand All @@ -252,7 +254,7 @@ def create_hb_stream(self, kernel_id):
=======
stream : ZMQStream
"""
hb_stream = self._create_connected_stream(kernel_id, zmq.REQ)
hb_stream = self._create_connected_stream(kernel_id, zmq.REQ, 'hb')
return hb_stream


Expand Down
6 changes: 6 additions & 0 deletions IPython/frontend/html/notebook/tests/test_kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ def _run_cinfo(self, km, transport, ip):
self.assertEqual(ip, cinfo['ip'])
self.assertTrue('stdin_port' in cinfo)
self.assertTrue('iopub_port' in cinfo)
stream = km.create_iopub_stream(kid)
stream.close()
self.assertTrue('shell_port' in cinfo)
stream = km.create_shell_stream(kid)
stream.close()
self.assertTrue('hb_port' in cinfo)
stream = km.create_hb_stream(kid)
stream.close()
km.shutdown_kernel(kid)

def test_tcp_lifecycle(self):
Expand Down

0 comments on commit cc7c183

Please sign in to comment.