From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [babel] [PATCH] Fix sh block execution in session Date: Sun, 05 Jun 2011 09:10:29 -0600 Message-ID: <87pqmsux0e.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:52850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTF6W-0004ki-U6 for emacs-orgmode@gnu.org; Sun, 05 Jun 2011 11:19:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QTF6U-0002aO-VX for emacs-orgmode@gnu.org; Sun, 05 Jun 2011 11:19:04 -0400 Received: from mail-pz0-f41.google.com ([209.85.210.41]:52404) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTF6U-0002aJ-F4 for emacs-orgmode@gnu.org; Sun, 05 Jun 2011 11:19:02 -0400 Received: by pzk4 with SMTP id 4so1778993pzk.0 for ; Sun, 05 Jun 2011 08:19:01 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Julien Barnier Cc: emacs-orgmode@gnu.org Hi Julien, Thanks for this patch, the current method of waiting for output in shell code blocks could certainly use improvement. After a series of simple tests I can confirm that this does appear to work for me. I have a couple of questions. 1. do you have a minimal example of a shell code block which works after your patch but not before? 2. I assume that the changes to ob-comit were required for your ob-sh changes to work and were not intended to affect other languages? 3. When switching the order of the prompt and eoe check in ob-comint, did you try *only* looking for the eoe indicator? It seems to me that once that is present the check for a followup prompt may not be required and it may make sense to simply remove that code. All in all I agree that the ob-sh changes look like an improvement and should be applied. I'm less sure of the changes to ob-comint, simply because I don't understand the mechanism through which swapping the regexp checks changes behavior. However if the ob-sh changes depend upon the ob-comint changes there is no point in applying them piecemeal. Situations like this (innocuous looking changes with potentially wide-ranging potential implications) make me wish Babel had a more mature and better-maintained test suite. Thanks -- Eric Julien Barnier writes: > Hi, > > When evaluating shell code blocks in org-babel, the execution seems to hang > indefinitely. The following patch is trying to fix this problem by modifying > the way shell code is send to comint and the way the end-of-evaluation > indicator is looking for. > > As I am far from an emacs lisp expert and as the patch modifies the widely use > org-babel-comint-with-output function, it certainly needs some testing. I've > made some tests with shell and R code blocks, but I'm not sure it's enough. > > Thanks ! > > Julien > > > Fix sh block execution in a session > > * lisp/ob-sh.el (org-babel-sh-evaluate) : when sending input to comint, wait > until previous line execution is finished > * lisp/ob-comint.el (org-babel-comint-with-output) : when looking for > end-of-evaluation indicator, search forward for the indicator before searching > forward for the prompt > --- > lisp/ob-comint.el | 4 ++-- > lisp/ob-sh.el | 8 +++++++- > 2 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/lisp/ob-comint.el b/lisp/ob-comint.el > index d12ed47..21ff0f6 100644 > --- a/lisp/ob-comint.el > +++ b/lisp/ob-comint.el > @@ -93,9 +93,9 @@ or user `keyboard-quit' during execution of body." > (goto-char comint-last-input-end) > (not (save-excursion > (and (re-search-forward > - comint-prompt-regexp nil t) > + (regexp-quote ,eoe-indicator) nil t) > (re-search-forward > - (regexp-quote ,eoe-indicator) nil t))))) > + comint-prompt-regexp nil t))))) > (accept-process-output (get-buffer-process (current-buffer))) > ;; thought the following this would allow async > ;; background running, but I was wrong... > diff --git a/lisp/ob-sh.el b/lisp/ob-sh.el > index 10c08d4..b2d1591 100644 > --- a/lisp/ob-sh.el > +++ b/lisp/ob-sh.el > @@ -170,7 +170,13 @@ return the value of the last statement in BODY." > (session org-babel-sh-eoe-output t body) > (mapc > (lambda (line) > - (insert line) (comint-send-input nil t) (sleep-for 0.25)) > + (insert line) > + (comint-send-input nil t) > + (while (save-excursion > + (goto-char comint-last-input-end) > + (not (re-search-forward > + comint-prompt-regexp nil t))) > + (accept-process-output (get-buffer-process (current-buffer))))) > (append > (split-string (org-babel-trim body) "\n") > (list org-babel-sh-eoe-indicator)))) -- Eric Schulte http://cs.unm.edu/~eschulte/