astahlman / ob-async

Asynchronous src_block execution for org-babel
343 stars 32 forks source link

org-babel-python-command is ignored #65

Closed ning-y closed 3 years ago

ning-y commented 3 years ago

Checklist

Expected Behavior

If (setq org-babel-python-command "python3"), then ob-async executions should use python3.

Actual Behavior

ob-async executions still use python2.

Steps to Reproduce

  1. (setq org-babel-python-command "python3")
  2. Check version of python used by ob-async using import sys; print(sys.version_info) and :results output. For example,
#+begin_src python :async :results output
import sys
print(sys.version_info)
#+end_src

#+RESULTS:
: sys.version_info(major=2, minor=7, micro=13, releaselevel='final', serial=0)

#+begin_src python :results output
import sys
print(sys.version_info)
#+end_src

#+RESULTS:
: sys.version_info(major=3, minor=7, micro=0, releaselevel='final', serial=0)

Troubleshooting Artifacts

https://gist.githubusercontent.com/ning-y/63687521272d2489d5e3317de44017c7/raw/2adb271f8ff541f86ba3ba2abbf5d2f8a28ceb56/troubleshooting.org

astahlman commented 3 years ago

That's correct, org-babel-python-command won't be set in the async subprocess unless you set it in an ob-async-pre-execute-src-block-hook, like this:

  (add-hook 'ob-async-pre-execute-src-block-hook
            '(lambda ()
               (setq org-babel-python-command "python3")))

Confirmation that this works:

#+BEGIN_SRC emacs-lisp
    (setq org-babel-python-command "python3")
#+END_SRC

#+RESULTS:
: python3

Confirmation that *without* =:async=, it works as expected:

#+BEGIN_SRC python :results output
  import sys; print(sys.version)
#+END_SRC

#+RESULTS:
: 3.8.2 (default, Jul 16 2020, 14:00:26) 
: [GCC 9.3.0]

Confirmation that *with* =:async=, =org-babel-python-command= isn't
set:

#+BEGIN_SRC python :async :results output
  import sys; print(sys.version)
#+END_SRC

#+RESULTS:
: 2.7.18rc1 (default, Apr  7 2020, 12:05:55) 
: [GCC 9.3.0]

Now let's set =org-babel-python-command= in a pre-exec hook:

#+BEGIN_SRC emacs-lisp :results silent
  (add-hook 'ob-async-pre-execute-src-block-hook
            '(lambda ()
               (setq org-babel-python-command "python3")))
#+END_SRC

And we can confirm that it now works as expected when =:async= is
enabled:

#+BEGIN_SRC python :async :results output
  import sys; print(sys.version)
#+END_SRC

#+RESULTS:
: 3.8.2 (default, Jul 16 2020, 14:00:26) 
: [GCC 9.3.0]
astahlman commented 3 years ago

Just opened a PR that would make the pre-execute hook unnecessary. Care to try out this branch and make sure it works? https://github.com/astahlman/ob-async/pull/67

ning-y commented 3 years ago

It works! Thank you very much!

astahlman commented 3 years ago

Great, thanks for confirming! I'll go ahead and merge https://github.com/astahlman/ob-async/pull/67 and close this one.