mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-05 09:01:40 -05:00
ein-shared-output: Queue up requests ala deferred:$
Try to gracefully handle multiple calls to `ein:shared-output-eval-string' by wrapping calls to deferred:$. The deferred chain will not call `ein:cell-execute' if the cell is already running. Also did a bit of refactoring in ob-ein.
This commit is contained in:
parent
a8fc712ca8
commit
73747d86d9
2 changed files with 29 additions and 16 deletions
|
@ -1,3 +1,4 @@
|
|||
;; -*- lexical-binding: t -*-
|
||||
;;; ein-shared-output.el --- Output buffer for ein-connect.el
|
||||
|
||||
;; Copyright (C) 2012- Takafumi Arakaki
|
||||
|
@ -216,9 +217,19 @@ shared output buffer. You can open the buffer by the command
|
|||
(list code nil t kernel)))
|
||||
(unless kernel (setq kernel (ein:get-kernel-or-error)))
|
||||
(let ((cell (ein:shared-output-get-cell)))
|
||||
(apply #'ein:cell-execute cell kernel (ein:trim-indent code) popup args))
|
||||
(when verbose
|
||||
(ein:log 'info "Code \"%s\" is sent to the kernel." code)))
|
||||
;; If cell is already running, wait until it is finished
|
||||
;; before executing more code.
|
||||
(deferred:$
|
||||
(deferred:next
|
||||
(deferred:lambda ()
|
||||
(if (not (null (slot-value cell 'running)))
|
||||
(deferred:nextc (deferred:wait 50) self))))
|
||||
(deferred:nextc it
|
||||
(lambda ()
|
||||
(deferred:wait 100) ;; Give everyone a few milliseconds to breath.
|
||||
(apply #'ein:cell-execute cell kernel (ein:trim-indent code) popup args)
|
||||
(when verbose
|
||||
(ein:log 'info "Code \"%s\" is sent to the kernel." code)))))))
|
||||
|
||||
|
||||
;;; Generic getter
|
||||
|
|
|
@ -188,21 +188,23 @@ jupyter kernels.
|
|||
(org-babel-ein-process-outputs (slot-value cell 'outputs) params)))))
|
||||
(deferred:nextc it
|
||||
(lambda (formatted-result)
|
||||
(message "Finished deferred ein execution: %s" name)
|
||||
(with-current-buffer buffer
|
||||
(save-excursion
|
||||
(org-babel-goto-named-result name)
|
||||
(search-forward (format "[[ob-ein-async-running: %s]]" name))
|
||||
(replace-match formatted-result)
|
||||
(org-redisplay-inline-images)
|
||||
;; (when (member "drawer" (cdr (assoc :result-params params)))
|
||||
;; ;; open the results drawer
|
||||
;; (org-babel-goto-named-result name)
|
||||
;; (forward-line)
|
||||
;; (org-flag-drawer nil))
|
||||
)))))
|
||||
(ein:ob-ein--execute-async-update formatted-result buffer name))))
|
||||
(format "[[ob-ein-async-running: %s]]" name)))
|
||||
|
||||
(defun ein:ob-ein--execute-async-update (formatted-result buffer name)
|
||||
(message "Finished deferred ein execution: %s" name)
|
||||
(with-current-buffer buffer
|
||||
(save-excursion
|
||||
(org-babel-goto-named-result name)
|
||||
(search-forward (format "[[ob-ein-async-running: %s]]" name))
|
||||
(replace-match formatted-result)
|
||||
(org-redisplay-inline-images)
|
||||
;; (when (member "drawer" (cdr (assoc :result-params params)))
|
||||
;; ;; open the results drawer
|
||||
;; (org-babel-goto-named-result name)
|
||||
;; (forward-line)
|
||||
;; (org-flag-drawer nil))
|
||||
)))
|
||||
|
||||
(defun ein:ob-ein--execute (full-body session-kernel processed-params)
|
||||
(ein:shared-output-eval-string full-body nil nil session-kernel)
|
||||
|
|
Loading…
Add table
Reference in a new issue