mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 15:41:37 -05:00
Better handling of when to remove requests from a client's request table
For each message received in response to a request, record the `last-message-time` of any received messages for a request. When a request's `idle-received-p` field is non-nil and the `last-message-time` is larger than some number of seconds, remove the request from the request table.
This commit is contained in:
parent
62691611e4
commit
8f774120c9
2 changed files with 16 additions and 4 deletions
|
@ -132,6 +132,7 @@ from the kernel.")
|
||||||
(-id)
|
(-id)
|
||||||
(time (current-time))
|
(time (current-time))
|
||||||
(idle-received-p nil)
|
(idle-received-p nil)
|
||||||
|
(last-message-time nil)
|
||||||
(run-handlers-p t)
|
(run-handlers-p t)
|
||||||
(callbacks))
|
(callbacks))
|
||||||
|
|
||||||
|
|
|
@ -612,6 +612,18 @@ that if no TIMEOUT is given, it defaults to
|
||||||
(declare (indent 1))
|
(declare (indent 1))
|
||||||
(jupyter-wait-until req msg-type #'identity timeout))
|
(jupyter-wait-until req msg-type #'identity timeout))
|
||||||
|
|
||||||
|
(defun jupyter--drop-idle-requests (client)
|
||||||
|
(cl-loop
|
||||||
|
with requests = (oref client requests)
|
||||||
|
with ctime = (current-time)
|
||||||
|
for req in (hash-table-values requests)
|
||||||
|
for ltime = (jupyter-request-last-message-time req)
|
||||||
|
for id = (jupyter-request-id req)
|
||||||
|
when (and (jupyter-request-idle-received-p req)
|
||||||
|
(> (float-time (time-subtract ctime ltime)) 60))
|
||||||
|
;; Don't remove the `jupyter-missing-request'
|
||||||
|
unless (equal id "") do (remhash id requests)))
|
||||||
|
|
||||||
(cl-defmethod jupyter-handle-message ((client jupyter-kernel-client) channel)
|
(cl-defmethod jupyter-handle-message ((client jupyter-kernel-client) channel)
|
||||||
"Process a message on CLIENT's CHANNEL.
|
"Process a message on CLIENT's CHANNEL.
|
||||||
When a message is received from the kernel, the
|
When a message is received from the kernel, the
|
||||||
|
@ -645,6 +657,7 @@ are taken:
|
||||||
;; TODO: Would we always want this?
|
;; TODO: Would we always want this?
|
||||||
(when (eq (oref channel type) :iopub)
|
(when (eq (oref channel type) :iopub)
|
||||||
(jupyter-handle-message channel client nil msg))
|
(jupyter-handle-message channel client nil msg))
|
||||||
|
(setf (jupyter-request-last-message-time req) (current-time))
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(jupyter--run-callbacks req msg)
|
(jupyter--run-callbacks req msg)
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
|
@ -653,10 +666,8 @@ are taken:
|
||||||
;; Checking for pmsg-id prevents the removal of
|
;; Checking for pmsg-id prevents the removal of
|
||||||
;; `jupyter-missing-request' for the client
|
;; `jupyter-missing-request' for the client
|
||||||
(when (and pmsg-id (jupyter-message-status-idle-p msg))
|
(when (and pmsg-id (jupyter-message-status-idle-p msg))
|
||||||
(setf (jupyter-request-idle-received-p req) t)
|
(setf (jupyter-request-idle-received-p req) t))
|
||||||
;; TODO: Messages associated with the request might still be
|
(jupyter--drop-idle-requests client)))))))
|
||||||
;; received when the request is removed from the requests table.
|
|
||||||
(remhash pmsg-id requests))))))))
|
|
||||||
|
|
||||||
;;; STDIN message requests/handlers
|
;;; STDIN message requests/handlers
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue