Function: org-babel-python-async-evaluate-session

org-babel-python-async-evaluate-session is a byte-compiled function defined in ob-python.el.gz.

Signature

(org-babel-python-async-evaluate-session SESSION BODY &optional RESULT-TYPE RESULT-PARAMS)

Documentation

Asynchronously evaluate BODY in SESSION.

Returns a placeholder string for insertion, to later be replaced by org-babel-comint-async-filter.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-python.el.gz
(defun org-babel-python-async-evaluate-session
    (session body &optional result-type result-params)
  "Asynchronously evaluate BODY in SESSION.
Returns a placeholder string for insertion, to later be replaced
by `org-babel-comint-async-filter'."
  (org-babel-comint-async-register
   session (current-buffer)
   "ob_comint_async_python_\\(.+\\)_\\(.+\\)"
   'org-babel-chomp 'org-babel-python-async-value-callback)
  (let ((python-shell-buffer-name (org-babel-python-without-earmuffs session)))
    (pcase result-type
      (`output
       (let ((uuid (md5 (number-to-string (random 100000000)))))
         (with-temp-buffer
           (insert (format org-babel-python-async-indicator "start" uuid))
           (insert "\n")
           (insert body)
           (insert "\n")
           (insert (format org-babel-python-async-indicator "end" uuid))
           (python-shell-send-buffer))
         uuid))
      (`value
       (let ((tmp-results-file (org-babel-temp-file "python-"))
             (tmp-src-file (org-babel-temp-file "python-")))
         (with-temp-file tmp-src-file (insert body))
         (with-temp-buffer
           (insert (org-babel-python-format-session-value tmp-src-file tmp-results-file result-params))
           (insert "\n")
           (insert (format org-babel-python-async-indicator "file" tmp-results-file))
           (python-shell-send-buffer))
         tmp-results-file)))))