astahlman / ob-async

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

ob-async doesn't support :var #60

Open dzfranklin opened 4 years ago

dzfranklin commented 4 years ago

Checklist

Expected Behavior

I can use #+NAME: and :var to pass the result of one block to another block even if the first block is :async

Actual Behavior

Even after the block finishes executing and the result is shown, #<process emacs> is stored under the name of the block. For example:


#+NAME: result-value
#+BEGIN_SRC shell :async
echo FooBar
#+END_SRC

#+RESULTS: result-value
: FooBar

#+BEGIN_SRC shell :var input_var=result-value
echo $input_var
#+END_SRC

#+RESULTS:
:results:
#<process emacs>
:end:

Steps to Reproduce

  1. Use #+NAME: result-value to store the result of an :async shell block's execution.
  2. Run the block and wait for execution to finish and the result to be displayed
  3. Pass that result to another shell block with :var input_var=result-value and write code to print the value of that variable in the block.
  4. Run the block and observe that the value passed is not the value of the first block's execution and instead #<process emacs> or possible #<process emacs <n>>

Troubleshooting Artifacts

troubleshooting.org and a direct link to the raw troubleshooting.org file that shows the results of the blocks.

Note

In the case of python (and possibly other languages) this breaks the code necessary to store the value. As a result, attempting to execute a block with a variable set by an async block will lead to a SyntaxError. I'm including this note because the first keywords I googled for related to this error, before I realized it was a broader issue.

  File "<stdin>", line 3
    input_var=#<process emacs>
                             ^
SyntaxError: invalid syntax
stardiviner commented 4 years ago

This is interesting usage of ob-async. I used this :var in non-ob-async case. I guess this is not easy to implement.

FelipeLema commented 3 years ago

Whoever works on this, should also consider the :cache header variable.

I'm having some inconsistency using it and I'm currently trying to stabilize/understand.

zhenwenc commented 3 years ago

Adding to this as its related to the :var header arg, ob-async causes variables to be evaluated twice, for example:

#+BEGIN_SRC sh :var INPUT=(read-string "Input: ")
echo $INPUT
#+END_SRC

The input prompt will show twice, and the second input value will be used.