shg / ob-julia-vterm.el

Org-babel support for Julia code blocks using julia-vterm
GNU General Public License v3.0
36 stars 6 forks source link

ob-julia-vterm creates error in process sentinel: async-handle-result: Recursive load: #25

Closed averter closed 4 months ago

averter commented 5 months ago

Strangely, after activating ob-julia-vterm all async source blocks stop working, e.g. when running

#+begin_src sh :async
  echo "Async does not works!"
#+end_src

#+RESULTS:
: 687a7ca347db311c7209daa609a8e1f1

I get the following error:

error in process sentinel: async-handle-result: Recursive load: "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org-id.elc", "/home/myusername/.emacs.d/elpa/ob-julia-vterm-20230815.2332/ob-julia-vterm.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org-id.elc", "/home/myusername/.emacs.d/elpa/ob-julia-vterm-20230815.2332/ob-julia-vterm.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org-id.elc", "/home/myusername/.emacs.d/elpa/ob-julia-vterm-20230815.2332/ob-julia-vterm.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org-id.elc", "/home/myusername/.emacs.d/elpa/ob-julia-vterm-20230815.2332/ob-julia-vterm.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc"
error in process sentinel: Recursive load: "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org-id.elc", "/home/myusername/.emacs.d/elpa/ob-julia-vterm-20230815.2332/ob-julia-vterm.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org-id.elc", "/home/myusername/.emacs.d/elpa/ob-julia-vterm-20230815.2332/ob-julia-vterm.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org-id.elc", "/home/myusername/.emacs.d/elpa/ob-julia-vterm-20230815.2332/ob-julia-vterm.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org-id.elc", "/home/myusername/.emacs.d/elpa/ob-julia-vterm-20230815.2332/ob-julia-vterm.elc", "/home/myusername/.emacs.d/elpa/org-9.6.24/org.elc"

My relevant org-mode configuration is

(use-package org
  :ensure t :ensure cdlatex :ensure adaptive-wrap :ensure ob-julia-vterm
  :commands (org)
  :pin gnu
  :mode (("\\.org$" . org-mode))
  :bind (("\C-cl" . org-store-link)     ;; Additional commands
         ("\C-ca" . org-agenda)
         ("\C-cr" . org-capture)
         ("C-c C-x <return> p" . org-mobile-push)
         ("C-c C-x <return> f" . org-mobile-pull))
  :hook (;; (org-mode . turn-on-org-cdlatex)
         (org-mode . adaptive-wrap-prefix-mode)     ; needed for correct display
         (org-mode . visual-line-mode)          ; needed for correct display
         (org-mode . org-indent-mode)           ; needed for correct display     
         (org-mode . turn-off-auto-fill)        ; needed for correct display
         (org-mode . (lambda () (emojify-mode -1))) ; disable emojis
         )
  :config
  (require 'org)
  ;; Active Org-Babel languages https://orgmode.org/manual/Evaluating-Code-Blocks.html#Evaluating-Code-Blocks
  (setq org-export-use-babel t)
  (org-babel-do-load-languages
   'org-babel-load-languages
   '((shell . t)
     (ruby . t)
     (awk . t)
     (matlab . t)
     (julia-vterm . t)
     (sql . t)
     (sqlite . t)
     (org . t)
     (R . t)
     (dot . t)
     (python . t)
     (latex . t)
     (ditaa . t)
     (C . t)))

  ;; Aliases to use "julia" rather than "julia-vterm" in the code blocks
  (defalias 'org-babel-execute:julia 'org-babel-execute:julia-vterm)
  (defalias 'org-babel-variable-assignments:julia 'org-babel-variable-assignments:julia-vterm)

  (setq python-shell-interpreter "python3")

  (setq org-babel-python-command "ipython3 --no-banner --classic --no-confirm-exit")
  (setq python-indent-guess-indent-offset t)  
  (setq python-indent-guess-indent-offset-verbose nil)
  (org-link-set-parameters
   "run"
   :follow #'org-babel-ref-resolve)
  (setq org-confirm-babel-evaluate (defun my-org-confirm-babel-evaluate (lang body)
                                     (not (or (string= lang "matlab")   ; don't ask for matlab
                                              (string= lang "julia")    ; don't ask for julia
                                              (string= lang "python"))) ; don't ask for python
                                     ))
  ;; CODE templates
  (add-to-list 'org-structure-template-alist
               '("mp" . "src matlab :session :exports both :file /tmp/chart.png :results file graphics"))
  (add-to-list 'org-structure-template-alist
               '("m" . "src matlab :results silent :session"))
  (add-to-list 'org-structure-template-alist
               '("j" . "src julia"))
  (add-to-list 'org-structure-template-alist
               '("py" . "src python :results output :session"))

  ;; Template Source code blocks (if missing uncomment)
  (require 'org-tempo))

and commenting the (julia-vterm . t) line makes async work again. I am using emacs 28.1, org 9.6.24, and ob-julia-vterm 20230815.2332. Thanks in advance.

shg commented 4 months ago

Thank you for the report. It helps to understand what's going on.

I assume you are using a 3rd party package, ob-async. I don't use ob-async, but the error you are seeing seems to occur when ob-async starts an Emacs sub-process.

I haven't seen the details of ob-async code, but as far as I understand, it uses async.el to launch an Emacs sub-process, then loads necessary settings to that Emacs sub-process. This process of starting the Emacs sub-process is different from the normal Emacs startup and seems to cause the error that does not occur in the normal Emacs startup.

So, I'd like to clarify that the issue you see is not a general issue that would affect all asynchronous org babel execution. The ob-python distributed with Org natively supports async execution, and the ob-python async execution works without a problem with ob-julia-vterm enabled. By the way, async execution is also natively implemented (in a different way) in ob-julia-vterm.

So far I assume the reported issue seems like a problem that ob-async should handle. But I'll keep checking it and see if there is anything I can do on the ob-julia-vterm side.

averter commented 4 months ago

Thanks @shg, this is helpful. Indeed, if I don't load ob-async there are no errors; however, I cannot then run org-babel blocks of certain languages asynchronously, i.e., emacs hangs when I execute a source block which takes some time, e.g., this one

#+begin_src sh :async
  sleep 10
  echo "Async does not works!"
#+end_src

Although certain languages, such as python as you said, might still work with the native async.

shg commented 4 months ago

@averter I found a possible workaround.

You can remove julia-vterm from the org-babel-load-languages variable. And if you want to use ob-julia-vterm, load it individually just by calling (require 'ob-julia-vterm) in your init file or somewhere.

It seems that the error you reported occurs when ob-async calls org-babel-do-load-languages function in the spawned Emacs sub-process. And loading ob-* file directly without using org-babel-load-languages is totally fine according to the Org documentation.

https://orgmode.org/manual/Languages.html

averter commented 4 months ago

It works. Brilliant. Thank you very much!