From a4d95aab80f33d8292bf5dce9f687379ca0a0d4e Mon Sep 17 00:00:00 2001 From: Nathaniel Nicandro Date: Tue, 25 Jun 2019 02:16:57 -0500 Subject: [PATCH] jupyter-handle-message: Drop idle messages less frequently This accounts for idle messages being dropped before a request's reply message. In such a case, the request is dropped from the client's request table before the handlers/callbacks of the request get a chance to handle the reply message. --- jupyter-client.el | 8 ++++++-- jupyter-repl.el | 11 ++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/jupyter-client.el b/jupyter-client.el index 89209e3..b9fdab7 100644 --- a/jupyter-client.el +++ b/jupyter-client.el @@ -697,8 +697,12 @@ are taken: ;; consider REQ as having received an idle message in ;; this case. (eq (jupyter-message-type msg) :shutdown-reply)) - (setf (jupyter-request-idle-received-p req) t)) - (jupyter--drop-idle-requests client))))))) + ;; Order matters here. We want to remove idle requests *before* + ;; setting another request idle to account for idle messages + ;; coming in out of order, e.g. before their respective reply + ;; messages. + (jupyter--drop-idle-requests client) + (setf (jupyter-request-idle-received-p req) t)))))))) ;;; Channel handler macros diff --git a/jupyter-repl.el b/jupyter-repl.el index ba2bb5c..38ba3b2 100644 --- a/jupyter-repl.el +++ b/jupyter-repl.el @@ -1707,15 +1707,8 @@ Return the buffer switched to." ;; ring. (ring-insert jupyter-repl-history 'jupyter-repl-history) (let ((jupyter-inhibit-handlers '(:status))) - ;; Wait until we get an idle response since the call to - ;; `jupyter-repl-sync-execution-state' below will be considered the last - ;; request the client made. If an idle message for this history request - ;; is received before the reply, the reply message won't ever be - ;; received since the idle message will cause the request to be dropped - ;; if the request isn't the last request the client made. - (jupyter-wait-until-idle - (jupyter-send-history-request jupyter-current-client - :n jupyter-repl-history-maximum-length :raw nil :unique t))) + (jupyter-send-history-request jupyter-current-client + :n jupyter-repl-history-maximum-length :raw nil :unique t)) (erase-buffer) ;; Add local hooks (add-hook 'kill-buffer-query-functions #'jupyter-repl-kill-buffer-query-function nil t)