I would like to asynchronously run code blocks in org mode.
My org mode version (org-version
output) is: Org mode version 9.2.1 (9.2.1-23-g126a37-elpa @ /home/user/.emacs.d/elpa/org-9.2.2/)
I followed some instructions on this blog: http://cachestocaches.com/2018/6/org-literate-programming/
I installed ob-async
.
I have a very simple Python code block in my org mode file:
#+BEGIN_SRC python :results output :async
import random
random.seed(1)
print("Hello World! Here's a random number: {}".format(random.random()))
#+END_SRC
#+RESULTS:
: f6d3fcf77d5cbec033f91b7dc23ebfe5
The result looks weird and every time I try to run the code block I see a messages in the messages buffer:
executing Python code block...
error in process sentinel: async-handle-result: Symbol’s value as variable is void: seq-random-elt
error in process sentinel: Symbol’s value as variable is void: seq-random-elt
I could not find anything helpful about this error so far.
How can I get asynchronous code execution from org source blocks to work properly?
Edit
I tried the following using emacs -Q
startup:
In my *scratch*
buffer I have the following content:
;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.
(require 'package)
(package-initialize)
(require 'ob-async)
(setq org-babel-load-languages
(quote
((emacs-lisp . t)
(python . t)
(scheme . t)
(sh . t))))
Then I press C-j
to evaluate.
Then I open my .org
file, which has the following source block and run the source block:
* Async Code Exec
Async package has issues and does not work?
#+BEGIN_SRC python :results output :async
import random
import time
random.seed(1)
time.sleep(5)
print("Hello World! Here's a random number: {}".format(random.random()))
#+END_SRC
#+RESULTS:
: Hello World! Here's a random number: 0.13436424411240122
The result is, that the time.sleep(5)
blocks emacs and is not run asynchronously. However, at least the result is fine, even if that was not the main reason for creating this question.
The same blocking behavior happens when I try it with an elisp source block:
#+BEGIN_SRC elisp :results output :async
(progn (sleep-for 5) (print 1))
#+END_SRC
#+RESULTS:
:
: 1
Edit 2
- My Emacs version is:
GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.21)
.
Edit 3
Running the following code also results in seq-random-elt
being void error:
(async-start
;; What to do in the child process
(lambda ()
(message "This is a test")
(sleep-for 3)
222)
;; What to do when it finishes
(lambda (result)
(message "Async process done, result should be 222: %s" result)))
The error:
executing Elisp code block...
error in process sentinel: async-handle-result: Symbol’s value as variable is void: seq-random-elt
error in process sentinel: Symbol’s value as variable is void: seq-random-elt
Edit 4
Here is the issue on Github, which I created for the problem: https://github.com/astahlman/ob-async/issues/55
Edit 5
Sorry for asking this obviously bad question ...
(progn (sleep-for 1) (print 1)
? You could also try requiring the seq library.emacs -Q
I have no setup for Python, so I tried your elisp. The result was, that it did not run asynchronously. I guess that is, becauseob-async
does not load when I run emacs like that and the:async
is ignored. I also cannot eval(require 'ob-async)
then, because "Cannot open load file: No such file or directory, ob-async". However, when I start emacs with my configuration (where I do requireob-async
) it does not show any error about not being able to find it.(require 'package)
,(package-initialize)
and(require 'ob-async)
in addition to yourorg-babel-load-languages
settings. Then eval the buffer and try the example above. If it works then you will have to bisect your init file to find out what part of your configuration is causing the problem. If it still fails I would suggest re-installing Org with the instructions here.emacs -Q
the:async
is ignored, but at least the output is no longer strange.