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
print("Hello World! Here's a random number: {}".format(random.random()))

: 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?


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)
(require 'ob-async)

(setq org-babel-load-languages
       ((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

print("Hello World! Here's a random number: {}".format(random.random()))

: 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))

: 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:

   ;; What to do in the child process
   (lambda ()
     (message "This is a test")
     (sleep-for 3)

   ;; 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

  • I don't see the error. Have you tried with emacs -Q, and does it work with emacs-lisp? For example: (progn (sleep-for 1) (print 1)? You could also try requiring the seq library. – jagrg Mar 31 at 14:25
  • @jagrg With 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, because ob-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 require ob-async) it does not show any error about not being able to find it. – Zelphir Mar 31 at 22:03
  • 1
    With emacs -Q switch to the scratch buffer and add only the configuration you need. For example, you might need (require 'package), (package-initialize) and (require 'ob-async) in addition to your org-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. – jagrg Apr 1 at 11:48
  • @jagrg I will add results of those tests to the original post. TLDR: When doing that with emacs -Q the :async is ignored, but at least the output is no longer strange. – Zelphir Apr 1 at 22:17
  • Are you able to run the example here under async-start? – jagrg Apr 1 at 23:06

I believe the answer is essentially that ob-async has a bug (either with how it implements this feature, or with its stated minimum supported verion of Emacs).

  • The user is running Emacs 25.2.2
  • seq-random-elt was introduced in Emacs 26
  • ob-async states emacs-24.4 as its minimum requirement

Most likely this will be resolved upstream in https://github.com/astahlman/ob-async/issues/55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.