Hi Jack,
I love the look of this! Thanks for submitting a patch. Sorry it's taken so long for someone to take a look at it, I think a lot of the 'main' Org people have been pretty busy over the last few months. I just tried to give this a shot. First up, I had to remove the ORG-NEWS part of the patch to be able to provide it. It would be nice if you could update the patch so this applies cleanly. #+begin_example error: patch failed: etc/ORG-NEWS:88 error: etc/ORG-NEWS: patch does not apply #+end_example To test this, after applying your patch (with ORG-NEWS removed), I started emacs -Q, loaded Org, and opened a new file. I was initially unable to get this to seem to work, until I changed the :results type to "output". See a excerpt from my test file below: ----- excerpt start ----- #+begin_src python :async :session blah :results output from time import sleep a=2 sleep(2) print("Hi") #+end_src #+RESULTS: : Hi #+begin_src python :async :session blah return(a) #+end_src #+RESULTS: : /tmp/babel-62cQRX/python-EfJ4o4 #+begin_src python :async :session blah :results output print(a) #+end_src #+RESULTS: : 2 ----- excerpt end ----- I'm surprised this didn't work with the non-output block though. Other than this, I'm rather happy to see that when I tried to execute two long running blocks at once, the second one was not executed until the first completed :) Finally, I see that this requires :session to be set in order to work. Might it be possible to have this work for non-session blocks too? It seems odd that what I'd imagine is the harder case (session blocks) is supported, but one-shot (non-session) blocks aren't. Thanks again for your work, and I look forward to seeing what else you have in the future! -- Timothy p.s. After this is merged, it would be great to see support for other languages grow :) Jack Kamm <jackk...@gmail.com> writes: > This patch adds asynchronous evaluation for session blocks in > Python. It also adds functionality to implement async session eval for > other languages using ob-comint.el. > > To test the attached patch, add ":async" to a Python session block > with a long computation (or "time.sleep") in it. Upon evaluation, your > Emacs won't freeze to wait for the result -- instead, a placeholder > will be inserted, and replaced with the true result when it's ready. > > I'll note how this is different from some related projects. ob-async > implements asynchronous evaluation for Babel, but it doesn't work with > sessions. emacs-jupyter, ein, and ob-ipython all implement > asynchronous session evaluation, but only for Jupyter kernels. Jupyter > is great for some cases, but sometimes I prefer to use the built-in > org-babel languages without jupyter. > > The new functionality is mainly implemented in > `org-babel-comint-async-filter', which I've defined in ob-comint.el, > and added as a hook to `comint-output-filter-functions'. Whenever new > output is added to the comint buffer, the filter scans for an > indicator token (this is inspired by > `org-babel-comint-with-output'). Upon encountering the token, the > filter uses a regular expression to extract a UUID or temp-file > associated with the result, then searches for the appropriate location > to add the result to. > > This is my 2nd attempt at this patch [0]. I have also ported it to an > external package [1], but would like to have this functionality in Org > proper, to permit better code reuse between async and sync > implementations. The external package also includes an R > implementation that I regularly use, as well as a Ruby implementation, > but I've left these out to keep this initial patch smaller, and also I > need to confirm copyright assignment on the Ruby implementation which > was externally contributed. > > [0] > https://orgmode.org/list/87muj04xim.fsf@jaheira.i-did-not-set--mail-host-address--so-tickle-me/ > [1] https://github.com/jackkamm/ob-session-async