From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christophe Rhodes Subject: [patch] race condition in org-babel R Date: Fri, 20 May 2011 12:21:24 +0100 Message-ID: <87sjs9wrbf.fsf@cantab.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:35956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNNlo-0001qy-P0 for emacs-orgmode@gnu.org; Fri, 20 May 2011 07:21:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QNNln-0008Hx-OU for emacs-orgmode@gnu.org; Fri, 20 May 2011 07:21:28 -0400 Received: from relay.ptn-ipout01.plus.net ([212.159.7.35]:3564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNNln-0008Hn-J5 for emacs-orgmode@gnu.org; Fri, 20 May 2011 07:21:27 -0400 Received: from [81.174.155.115] (helo=lambda) by outmx02.plus.net with esmtp (Exim) id 1QNNll-0005Kc-I6 for emacs-orgmode@gnu.org; Fri, 20 May 2011 12:21:25 +0100 Received: from csr21 by lambda with local (Exim 4.72) (envelope-from ) id 1QNNlk-0005Lo-7V for emacs-orgmode@gnu.org; Fri, 20 May 2011 12:21:24 +0100 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: emacs-orgmode@gnu.org --=-=-= Hi, A substantial fraction of times when exporting my org-babel document (with many R session code blocks), I get "code block produced no value". I think this is because of a race condition between waiting for the transfer.file to exist and actually populating it with output; the scenario is: 1. write.table() creates its output file 2. emacs notices its existence, and reads it 3. write.table() gets round to writing .Last.value to the file. The attached patch has made exporting much more reliable for me. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-fix-race-condition-in-ob-R-write-object-command.patch >From 62aa24a7979d687dd5136775004ff7ff5584564a Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Fri, 20 May 2011 12:12:45 +0100 Subject: [PATCH] fix race condition in ob-R write-object-command * lisp/ob-R.el (org-babel-R-write-object-command): write the object to a temporary file, then move that temporary file in place to transfer.file --- lisp/ob-R.el | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 713d59f..8421c69 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -227,7 +227,7 @@ current code buffer." (defvar org-babel-R-eoe-indicator "'org_babel_R_eoe'") (defvar org-babel-R-eoe-output "[1] \"org_babel_R_eoe\"") -(defvar org-babel-R-write-object-command "{function(object, transfer.file) {object;invisible(if(inherits(try(write.table(object, file=transfer.file, sep=\"\\t\", na=\"nil\",row.names=%s, col.names=%s, quote=FALSE), silent=TRUE),\"try-error\")) {if(!file.exists(transfer.file)) file.create(transfer.file)})}}(object=%s, transfer.file=\"%s\")") +(defvar org-babel-R-write-object-command "{function(object, transfer.file) {tfile <- tempfile();invisible(if(inherits(try({write.table(object, file=tfile, sep=\"\\t\", na=\"nil\",row.names=%s, col.names=%s, quote=FALSE); file.rename(tfile,transfer.file)}, silent=TRUE),\"try-error\")){if(!file.exists(transfer.file)) file.create(transfer.file)})}}(object=%s, transfer.file=\"%s\")") (defun org-babel-R-evaluate (session body result-type column-names-p row-names-p) -- 1.7.2.5 --=-=-= Best, Christophe --=-=-=--