From a53d2c8489b3e5dff7b2e1d51e6186b2b9245b96 Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 12 Jul 2018 23:45:56 -0500 Subject: [PATCH] flush iopub before sending restarting/dead status messages to ensure (approximately) that all messages from the stopped kernel are delivered before the dead/restarting message --- notebook/services/kernels/handlers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/notebook/services/kernels/handlers.py b/notebook/services/kernels/handlers.py index 359d6fafc2..9b751adb92 100644 --- a/notebook/services/kernels/handlers.py +++ b/notebook/services/kernels/handlers.py @@ -456,6 +456,12 @@ def on_close(self): self._close_future.set_result(None) def _send_status_message(self, status): + iopub = self.channels.get('iopub', None) + if iopub and not iopub.closed(): + # flush IOPub before sending a restarting/dead status message + # ensures proper ordering on the IOPub channel + # that all messages from the stopped kernel have been delivered + iopub.flush() msg = self.session.msg("status", {'execution_state': status} )