From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Karl Voit <news1142@Karl-Voit.at>
Cc: emacs-orgmode@gnu.org
Subject: Re: asynchronous python code blocks in org-mode
Date: Mon, 30 Nov 2015 16:06:51 -0500 [thread overview]
Message-ID: <m2poyrqjro.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <2015-11-30T12-27-30@devnull.Karl-Voit.at>
Karl Voit writes:
> * John Kitchin <jkitchin@andrew.cmu.edu> wrote:
>> Hi everyone,
>
> Hi John!
>
>> I worked out some ideas on running Python blocks asynchronously in
>> org-mode, while seeing the output of the code, /and/ still capturing the
>> output in org-mode!
>
> Found the link to your video + blog on Twitter. On the weekend, I
> watched it with big eyes and tried your code on my side as well:
> great work!
>
>> It seems to work pretty well as a proof of concept, but the present
>> approach has some limitations, e.g. no sessions, no src-block :var, and
>> maybe others. These might be fixable at some point.
>>
>> Anyway, I thought I would share it, to see if anyone has thoughts on
>> it, and in case it looks useful to you.
>
> I'm loving it.
>
> I'd love to see this async method for shell script as well. Many
> shell snippets I am using do take some time: backup, audio
> conversion, bulk image conversion, ...
It turns out to be pretty trivial to modify this for sh. Change change
org-babel-variable-assignments:python to
org-babel-variable-assignments:sh and python
to bash, and rename the function to org-babel-async-execute:sh, and you
should have it.
If you don't mind redefining an org command, this will let you put
:async in the header to trigger the asynchronous mode, otherwise, run
the usual way:
(defun org-babel-execute:sh (body params)
"Execute a block of Shell commands with Babel.
This function is called by `org-babel-execute-src-block'."
(let* ((session (org-babel-sh-initiate-session
(cdr (assoc :session params))))
(async (assoc :async params))
(stdin (let ((stdin (cdr (assoc :stdin params))))
(when stdin (org-babel-sh-var-to-string
(org-babel-ref-resolve stdin)))))
(full-body (org-babel-expand-body:generic
body params (org-babel-variable-assignments:sh params))))
(if async
;; run asynchronously
(org-babel-async-execute:sh)
;; else run regularly
(org-babel-reassemble-table
(org-babel-sh-evaluate session full-body params stdin)
(org-babel-pick-name
(cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
(org-babel-pick-name
(cdr (assoc :rowname-names params)) (cdr (assoc :rownames
params)))))))
I have not thought about sessions and asynchronous execution. It would
mean a queue and a different way to pass code to the process, which I
have not thought through yet. What to do when there are dependencies for
example,...
>
> 1) How big is the chance that we're going to see async babel block
> execution by default in a future org-mode release?
>
> 2) In the meantime: Wouldn't it be nice to have additional
> source-block definitions like python + apython (for asynchronous
> python) or sh + ash?
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
next prev parent reply other threads:[~2015-11-30 21:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-20 16:52 asynchronous python code blocks in org-mode John Kitchin
2015-11-30 11:38 ` Karl Voit
2015-11-30 21:06 ` John Kitchin [this message]
2015-12-01 20:19 ` Tom
2015-12-01 23:07 ` John Kitchin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2poyrqjro.fsf@andrew.cmu.edu \
--to=jkitchin@andrew.cmu.edu \
--cc=emacs-orgmode@gnu.org \
--cc=news1142@Karl-Voit.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).