Skip to content

Commit

Permalink
hookup restart callbacks in open
Browse files Browse the repository at this point in the history
instead of in `create_stream`, which is not called on reconnect
  • Loading branch information
minrk committed Oct 4, 2017
1 parent 38224fb commit 68602fa
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions notebook/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ def create_stream(self):
meth = getattr(km, 'connect_' + channel)
self.channels[channel] = stream = meth(self.kernel_id, identity=identity)
stream.channel = channel
km.add_restart_callback(self.kernel_id, self.on_kernel_restarted)
km.add_restart_callback(self.kernel_id, self.on_restart_failed, 'dead')

def request_kernel_info(self):
"""send a request for kernel_info"""
Expand Down Expand Up @@ -258,10 +256,11 @@ def _register_session(self):

def open(self, kernel_id):
super(ZMQChannelsHandler, self).open()
self.kernel_manager.notify_connect(kernel_id)
km = self.kernel_manager
km.notify_connect(kernel_id)

# on new connections, flush the message buffer
buffer_info = self.kernel_manager.get_buffer(kernel_id, self.session_key)
buffer_info = km.get_buffer(kernel_id, self.session_key)
if buffer_info and buffer_info['session_key'] == self.session_key:
self.log.info("Restoring connection for %s", self.session_key)
self.channels = buffer_info['channels']
Expand All @@ -284,6 +283,9 @@ def open(self, kernel_id):
self.close()
return

km.add_restart_callback(self.kernel_id, self.on_kernel_restarted)
km.add_restart_callback(self.kernel_id, self.on_restart_failed, 'dead')

for channel, stream in self.channels.items():
stream.on_recv_stream(self._on_zmq_reply)

Expand Down

0 comments on commit 68602fa

Please sign in to comment.