Skip to content

Commit a19319e

Browse files
authored
Merge pull request #572 from hex-inc/gt/reintroduce-539
Re-introduce #539, fix abort to not abort non-execute requests
2 parents 003ac85 + 983d570 commit a19319e

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

ipykernel/kernelbase.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141
CONTROL_PRIORITY = 1
4242
SHELL_PRIORITY = 10
43-
ABORT_PRIORITY = 20
4443

4544

4645
class Kernel(SingletonConfigurable):
@@ -182,10 +181,6 @@ def dispatch_control(self, msg):
182181
# Set the parent message for side effects.
183182
self.set_parent(idents, msg)
184183
self._publish_status('busy')
185-
if self._aborting:
186-
self._send_abort_reply(self.control_stream, msg, idents)
187-
self._publish_status('idle')
188-
return
189184

190185
header = msg['header']
191186
msg_type = header['msg_type']
@@ -233,16 +228,17 @@ def dispatch_shell(self, stream, msg):
233228
self.set_parent(idents, msg)
234229
self._publish_status('busy')
235230

236-
if self._aborting:
231+
msg_type = msg['header']['msg_type']
232+
233+
# Only abort execute requests
234+
if self._aborting and msg_type == 'execute_request':
237235
self._send_abort_reply(stream, msg, idents)
238236
self._publish_status('idle')
239237
# flush to ensure reply is sent before
240238
# handling the next request
241239
stream.flush(zmq.POLLOUT)
242240
return
243241

244-
msg_type = msg['header']['msg_type']
245-
246242
# Print some info about this message and leave a '--->' marker, so it's
247243
# easier to trace visually the message chain when debugging. Each
248244
# handler prints its message at the end.
@@ -792,16 +788,11 @@ def _abort_queues(self):
792788
stream.flush()
793789
self._aborting = True
794790

795-
self.schedule_dispatch(
796-
ABORT_PRIORITY,
797-
self._dispatch_abort,
798-
)
791+
def stop_aborting(f):
792+
self.log.info("Finishing abort")
793+
self._aborting = False
799794

800-
@gen.coroutine
801-
def _dispatch_abort(self):
802-
self.log.info("Finishing abort")
803-
yield gen.sleep(self.stop_on_error_timeout)
804-
self._aborting = False
795+
self.io_loop.add_future(gen.sleep(self.stop_on_error_timeout), stop_aborting)
805796

806797
def _send_abort_reply(self, stream, msg, idents):
807798
"""Send a reply to an aborted request"""

ipykernel/tests/test_message_spec.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def check(self, d):
114114
ExecuteReplyOkay().check(d)
115115
elif d['status'] == 'error':
116116
ExecuteReplyError().check(d)
117+
elif d['status'] == 'aborted':
118+
ExecuteReplyAborted().check(d)
117119

118120

119121
class ExecuteReplyOkay(Reply):
@@ -122,11 +124,16 @@ class ExecuteReplyOkay(Reply):
122124

123125

124126
class ExecuteReplyError(Reply):
127+
status = Enum(('error',))
125128
ename = Unicode()
126129
evalue = Unicode()
127130
traceback = List(Unicode())
128131

129132

133+
class ExecuteReplyAborted(Reply):
134+
status = Enum(('aborted',))
135+
136+
130137
class InspectReply(Reply, MimeBundle):
131138
found = Bool()
132139

@@ -348,6 +355,30 @@ def test_execute_stop_on_error():
348355
assert reply['content']['status'] == 'ok'
349356

350357

358+
def test_non_execute_stop_on_error():
359+
"""test that non-execute_request's are not aborted after an error"""
360+
flush_channels()
361+
362+
fail = '\n'.join([
363+
# sleep to ensure subsequent message is waiting in the queue to be aborted
364+
'import time',
365+
'time.sleep(0.5)',
366+
'raise ValueError',
367+
])
368+
KC.execute(code=fail)
369+
KC.kernel_info()
370+
KC.comm_info()
371+
KC.inspect(code="print")
372+
reply = KC.get_shell_msg(timeout=TIMEOUT) # execute
373+
assert reply['content']['status'] == 'error'
374+
reply = KC.get_shell_msg(timeout=TIMEOUT) # kernel_info
375+
assert reply['content']['status'] == 'ok'
376+
reply = KC.get_shell_msg(timeout=TIMEOUT) # comm_info
377+
assert reply['content']['status'] == 'ok'
378+
reply = KC.get_shell_msg(timeout=TIMEOUT) # inspect
379+
assert reply['content']['status'] == 'ok'
380+
381+
351382
def test_user_expressions():
352383
flush_channels()
353384

0 commit comments

Comments
 (0)