2

When I C-c C-c in a Python code block in Org mode:

#+BEGIN_SRC python :results value :session
  a = 4
  a + 13
#+END_SRC

It hangs with a message:

Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native-enable’ was t and "python" is not part of the ‘python-shell-completion-native-disabled-interpreters’ list.  Native completions have been disabled locally.  Disable showing Disable logging

It can be reproduced with emacs -Q with

(org-babel-do-load-languages
  'org-babel-load-languages
    '((python . t)))

I tried to debug this using M-x toggle-debug-on-quit:

Debugger entered--Lisp error: (quit)
  accept-process-output(#<process Python>)
  org-babel-python--send-string("*Python*" "import ast\nwith open('/var/folders/78/44lg7sv17db2...")
  org-babel-python-evaluate-session("*Python*" "a = 4\na + 13" value ("replace" "value"))
  org-babel-python-evaluate("*Python*" "a = 4\na + 13" value ("replace" "value") nil nil)
  org-babel-execute:python("a = 4\na + 13" ((:colname-names) (:rowname-names) (:result-params "replace" "value") (:result-type . value) (:results . "replace value") (:exports . "code") (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no") (:session)))
  org-babel-execute-src-block(nil ("python" "a = 4\na + 13" ((:colname-names) (:rowname-names) (:result-params "value" "replace") (:result-type . value) (:results . "value replace") (:exports . "code") (:session) (:tangle . "no") (:hlines . "no") (:noweb . "no") (:cache . "no")) "" nil 148 "(ref:%s)"))
  org-ctrl-c-ctrl-c(nil)
  funcall-interactively(org-ctrl-c-ctrl-c nil)
  call-interactively(org-ctrl-c-ctrl-c nil nil)
  command-execute(org-ctrl-c-ctrl-c)

but I'm new to emacs (started a week ago) and cannot extract any useful info from this log.

I thought perhaps this post is relevant, but it did not solve the issue.

Interestingly, when I do C-c C-c after manually starting the Python REPL via M-x run-python, it runs smoothly without any error or warning messages.

I'm using Emacs 28.1 in macOS 12.4 (using the Emacs plus distribution for macOS, if relevant). Python 3.10.0 is managed by Pyenv, which is installed via Homebrew. eshell correctly finds the installed Python.

Thanks in advance.


Update org-babel-python-command is "python". When I M-x run-python, it runs Python 3.10.0.

Jay Lee
  • 131
  • 5
  • What is the value of `org-babel-python-command`? Do `C-h v org-babel-python-command` to find out and then edit your question and add the information to your question (not in a comment). You can also try to switch to the `*Python*` buffer and see what the session output looks like. – NickD Jun 21 '22 at 15:20
  • BTW, in my case the value is `python3` on a Fedora 35 system and your code block works without any problem here. – NickD Jun 21 '22 at 15:21
  • 1
    @NickD Hi, I updated the post with the output of the commands. – Jay Lee Jun 21 '22 at 16:00
  • I don't know how comfortable you will be with this suggestion: since it seems that `accept-process-output` is hanging, I would modify its caller `org-babel-python--send-string` to call it wih a timeout argument: on line 362 or thereabouts of `ob-python.el`, call it like this: `...(accept-process-output (get-buffer-process (current-buffer)) 0.2)) ...` adding a 0.2 sec timeout. Then reevaluate the `defun` with `M-C-x` and see if the problem persists. I cannot pretend that this is a solution: if it works, it points to a process deadlock but why that is the case, I cannot guess. And even if ... – NickD Jun 23 '22 at 03:41
  • ... it does not hang, there is no guarantee that it will work properly. But I think it's a worthwhile experiment to try out. – NickD Jun 23 '22 at 03:42
  • 1
    There seems to be an identifiable pattern for this issue. I'm on macOS, Emacs 28.2. Issues seem to have arisen in the handling of the "session" header. In addition to the issue described above, I cannot seem to combine "session" and "async" headers properly - the async function never resolves. The fix suggested above by NickD doesn't seem to affect either issue described above in my own testing. Another instance reported: https://github.com/syl20bnr/spacemacs/issues/15620 – faulty_ram_sticks Sep 18 '22 at 04:33
  • I can confirm at least that downgrading to 27.2 does resolve, for me, the issue asked by Jay Lee. – faulty_ram_sticks Sep 18 '22 at 05:04
  • "In addition to the issue described above, I cannot seem to combine "session" and "async" headers properly - the async function never resolves." Apologies - don't mean to hijack, but for posterity, it seems this issue is unrelated - I realized that I was still requiring ob-async despite async functionality now being native to org. Removing that require fixes the issue in quotes. – faulty_ram_sticks Sep 18 '22 at 17:37

0 Answers0