Skip to content

Commit

Permalink
flush after sending replies
Browse files Browse the repository at this point in the history
to ensure that the reply is actually sent before we handle the next request
  • Loading branch information
minrk committed Feb 20, 2019
1 parent 9d7a743 commit fca4303
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ def dispatch_control(self, msg):
sys.stdout.flush()
sys.stderr.flush()
self._publish_status(u'idle')
# flush to ensure reply is sent
self.control_stream.flush(zmq.POLLOUT)

def should_handle(self, stream, msg, idents):
"""Check whether a shell-channel message should be handled
Expand Down Expand Up @@ -241,6 +243,9 @@ def dispatch_shell(self, stream, msg):
if self._aborting:
self._send_abort_reply(stream, msg, idents)
self._publish_status(u'idle')
# flush to ensure reply is sent before
# handling the next request
stream.flush(zmq.POLLOUT)
return

msg_type = msg['header']['msg_type']
Expand Down Expand Up @@ -276,6 +281,9 @@ def dispatch_shell(self, stream, msg):
sys.stdout.flush()
sys.stderr.flush()
self._publish_status(u'idle')
# flush to ensure reply is sent before
# handling the next request
stream.flush(zmq.POLLOUT)

def pre_handler_hook(self):
"""Hook to execute before calling message handler"""
Expand Down

0 comments on commit fca4303

Please sign in to comment.