Skip to content

Commit 7e11d8e

Browse files
authored
Nudge on the control channel instead of the shell (#628)
1 parent e5cb6c4 commit 7e11d8e

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

jupyter_server/services/kernels/handlers.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,16 @@ def create_stream(self):
131131
def nudge(self):
132132
"""Nudge the zmq connections with kernel_info_requests
133133
Returns a Future that will resolve when we have received
134-
a shell reply and at least one iopub message,
134+
a control reply and at least one iopub message,
135135
ensuring that zmq subscriptions are established,
136136
sockets are fully connected, and kernel is responsive.
137137
Keeps retrying kernel_info_request until these are both received.
138138
"""
139139
kernel = self.kernel_manager.get_kernel(self.kernel_id)
140140

141-
# Do not nudge busy kernels as kernel info requests sent to shell are
142-
# queued behind execution requests.
143-
# nudging in this case would cause a potentially very long wait
144-
# before connections are opened,
145-
# plus it is *very* unlikely that a busy kernel will not finish
146-
# establishing its zmq subscriptions before processing the next request.
147-
if getattr(kernel, "execution_state") == "busy":
148-
self.log.debug("Nudge: not nudging busy kernel %s", self.kernel_id)
149-
f = Future()
150-
f.set_result(None)
151-
return f
152-
153-
# Use a transient shell channel to prevent leaking
154-
# shell responses to the front-end.
155-
shell_channel = kernel.connect_shell()
141+
# Use a transient control channel to prevent leaking
142+
# control responses to the front-end.
143+
control_channel = kernel.connect_control()
156144
# The IOPub used by the client, whose subscriptions we are verifying.
157145
iopub_channel = self.channels["iopub"]
158146

@@ -172,13 +160,13 @@ def cleanup(_=None):
172160
"""Common cleanup"""
173161
loop.remove_timeout(nudge_handle)
174162
iopub_channel.stop_on_recv()
175-
if not shell_channel.closed():
176-
shell_channel.close()
163+
if not control_channel.closed():
164+
control_channel.close()
177165

178166
# trigger cleanup when both message futures are resolved
179167
both_done.add_done_callback(cleanup)
180168

181-
def on_shell_reply(msg):
169+
def on_control_reply(msg):
182170
self.log.debug("Nudge: shell info reply received: %s", self.kernel_id)
183171
if not info_future.done():
184172
self.log.debug("Nudge: resolving shell future: %s", self.kernel_id)
@@ -192,7 +180,7 @@ def on_iopub(msg):
192180
iopub_future.set_result(None)
193181

194182
iopub_channel.on_recv(on_iopub)
195-
shell_channel.on_recv(on_shell_reply)
183+
control_channel.on_recv(on_control_reply)
196184
loop = IOLoop.current()
197185

198186
# Nudge the kernel with kernel info requests until we get an IOPub message
@@ -213,15 +201,15 @@ def nudge(count):
213201
return
214202

215203
# check for closed zmq socket
216-
if shell_channel.closed():
204+
if control_channel.closed():
217205
self.log.debug("Nudge: cancelling on closed zmq socket: %s", self.kernel_id)
218206
finish()
219207
return
220208

221209
if not both_done.done():
222210
log = self.log.warning if count % 10 == 0 else self.log.debug
223211
log("Nudge: attempt %s on kernel %s" % (count, self.kernel_id))
224-
self.session.send(shell_channel, "kernel_info_request")
212+
self.session.send(control_channel, "kernel_info_request")
225213
nonlocal nudge_handle
226214
nudge_handle = loop.call_later(0.5, nudge, count)
227215

0 commit comments

Comments
 (0)