Skip to content

Commit d7ade66

Browse files
authored
nudge both the shell and control channels (#6290)
1 parent 2662634 commit d7ade66

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

notebook/services/kernels/handlers.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def nudge(self):
138138
"""Nudge the zmq connections with kernel_info_requests
139139
140140
Returns a Future that will resolve when we have received
141-
a shell reply and at least one iopub message,
141+
a shell or control reply and at least one iopub message,
142142
ensuring that zmq subscriptions are established,
143143
sockets are fully connected, and kernel is responsive.
144144
@@ -157,10 +157,12 @@ def nudge(self):
157157
f = Future()
158158
f.set_result(None)
159159
return f
160-
161160
# Use a transient shell channel to prevent leaking
162161
# shell responses to the front-end.
163162
shell_channel = kernel.connect_shell()
163+
# Use a transient control channel to prevent leaking
164+
# control responses to the front-end.
165+
control_channel = kernel.connect_control()
164166
# The IOPub used by the client, whose subscriptions we are verifying.
165167
iopub_channel = self.channels["iopub"]
166168

@@ -183,6 +185,8 @@ def cleanup(f=None):
183185
iopub_channel.stop_on_recv()
184186
if not shell_channel.closed():
185187
shell_channel.close()
188+
if not control_channel.closed():
189+
control_channel.close()
186190

187191
# trigger cleanup when both message futures are resolved
188192
both_done.add_done_callback(cleanup)
@@ -193,6 +197,12 @@ def on_shell_reply(msg):
193197
self.log.debug("Nudge: resolving shell future: %s", self.kernel_id)
194198
info_future.set_result(None)
195199

200+
def on_control_reply(msg):
201+
self.log.debug("Nudge: control info reply received: %s", self.kernel_id)
202+
if not info_future.done():
203+
self.log.debug("Nudge: resolving control future: %s", self.kernel_id)
204+
info_future.set_result(None)
205+
196206
def on_iopub(msg):
197207
self.log.debug("Nudge: IOPub received: %s", self.kernel_id)
198208
if not iopub_future.done():
@@ -202,6 +212,7 @@ def on_iopub(msg):
202212

203213
iopub_channel.on_recv(on_iopub)
204214
shell_channel.on_recv(on_shell_reply)
215+
control_channel.on_recv(on_control_reply)
205216
loop = IOLoop.current()
206217

207218
# Nudge the kernel with kernel info requests until we get an IOPub message
@@ -227,6 +238,12 @@ def nudge(count):
227238

228239
# check for closed zmq socket
229240
if shell_channel.closed():
241+
self.log.debug("Nudge: cancelling on closed zmq socket: %s", self.kernel_id)
242+
finish()
243+
return
244+
245+
# check for closed zmq socket
246+
if control_channel.closed():
230247
self.log.debug(
231248
"Nudge: cancelling on closed zmq socket: %s", self.kernel_id
232249
)
@@ -237,6 +254,7 @@ def nudge(count):
237254
log = self.log.warning if count % 10 == 0 else self.log.debug
238255
log("Nudge: attempt %s on kernel %s" % (count, self.kernel_id))
239256
self.session.send(shell_channel, "kernel_info_request")
257+
self.session.send(control_channel, "kernel_info_request")
240258
nonlocal nudge_handle
241259
nudge_handle = loop.call_later(0.5, nudge, count)
242260

0 commit comments

Comments
 (0)