I have developed a workflow for batch-export of org-mode files, and have come across an issue in which execution halts when using a python session. I'm using emacs 28.1 on MacOS 11.6.5 with Python 3.9.5.
Here's a minimal org-mode file (python-session.org
)
#+PROPERTY: header-args:python :exports both :eval yes :session
#+begin_src python :results output
import sys
print(sys.executable)
print(sys.version)
var = "from the first block"
#+end_src
#+begin_src python :results output
print(var)
#+end_src
..and some minimal code to export on batch mode
(let* ((infile (car (last command-line-args)))
(outfile (concat (file-name-sans-extension infile) ".html")))
(find-file infile)
(org-mode)
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(shell . t)
(python . t)))
(setq org-confirm-babel-evaluate nil)
(setq org-babel-python-command "python3")
(setq python-indent-offset 4)
(setq python-shell-completion-native-enable nil)
(setq python-indent-guess-indent-offset t)
(setq python-indent-guess-indent-offset-verbose nil)
(org-html-export-as-html)
(write-file outfile))
Here's the command to perform the export (and the resulting message):
% emacs --batch --load minimal-export.el --kill -- python-session.org
executing Python code block...
At this point the process hangs and must be interrupted.
The above command results in an exported html file when the :session
option is removed from the first line of the file:
% emacs --batch --load minimal-export.el --kill -- python-session.org
executing Python code block...
Code block evaluation complete.
executing Python code block...
Babel evaluation exited with code 1
Code block produced no output.
Cannot fontify source block (htmlize.el >= 1.34 required)
Cannot fontify source block (htmlize.el >= 1.34 required)
Any ideas on how to troubleshoot further?
GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.31, cairo version 1.17.4) of 2022-02-12
, so it may be a bug in Emacs 28.1. BTW, when I say no problem, I mean there is no hang. But the output of the Org Babel source block is messy; in particular, it is not an exact copy of what you would get when you run the program from the command line. For that reason alone, I avoid python sessions in Org Babel.