[Swift-commit] r4073 - SwiftApps/SwiftR/Swift/exec

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Feb 9 13:38:14 CST 2011


Author: tga
Date: 2011-02-09 13:38:14 -0600 (Wed, 09 Feb 2011)
New Revision: 4073

Modified:
   SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh
   SwiftApps/SwiftR/Swift/exec/SwiftRServer.R
Log:
Added error handling.


Modified: SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh	2011-02-09 19:17:27 UTC (rev 4072)
+++ SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh	2011-02-09 19:38:14 UTC (rev 4073)
@@ -91,7 +91,9 @@
   mkfifo $SLOTDIR/toR.fifo
   mkfifo $SLOTDIR/fromR.fifo
   chmod +x $RServerScript
-  PATH=.:$PATH $RServerScript $SLOTDIR >& $SLOTDIR/R.log &   # launch R server
+  echo "$0: INFO: Launching $RServerScript $SLOTDIR"
+  PATH=.:$PATH 
+  strace $RServerScript $SLOTDIR >& $SLOTDIR/R.log &   # launch R server
   # idletimer $SLOTDIR </dev/null >/dev/null 2>&1 & # R saves pid in R.pid for idletimer to kill it
   echo "$0: INFO: Launched $RServerScript $SLOTDIR Rscript"
 else
@@ -125,8 +127,15 @@
 
 echo dummy stderr response 1>&2 # FIXME - testing if this is the provider staging problem (not xfering zero len stderr)
 
-head -3 < $SLOTDIR/fromR.fifo # FIXME: Trim this down to 1 line for each call (or same # lines for each, in particular, for "quit")
+res=$(head -3 < $SLOTDIR/fromR.fifo) # FIXME: Trim this down to 1 line for each call (or same # lines for each, in particular, for "quit")
+echo "$res"
+# Test if R server reported an error
+if echo "$res" | grep -q '^ERROR:'
+then
+    exit 1
+fi
 
+
 echo DB: Got response
 
 rmdir $SLOTDIR/mutex

Modified: SwiftApps/SwiftR/Swift/exec/SwiftRServer.R
===================================================================
--- SwiftApps/SwiftR/Swift/exec/SwiftRServer.R	2011-02-09 19:17:27 UTC (rev 4072)
+++ SwiftApps/SwiftR/Swift/exec/SwiftRServer.R	2011-02-09 19:38:14 UTC (rev 4073)
@@ -2,6 +2,8 @@
 
 require(methods)
 argv = commandArgs(TRUE)
+print("SwiftRServer arguments:")
+print(argv)
 
 fifoDir = argv[1];  # FIXME: test for valid arguments
 
@@ -11,8 +13,8 @@
 
 SwiftRFifoServer <- function( fifoBasename )
 {
-  inFifoName = paste(fifoDir,"/toR.fifo",sep="")
-  outFifoName = paste(fifoDir,"/fromR.fifo",sep="")
+  inFifoName = file.path(fifoDir,"toR.fifo")
+  outFifoName = file.path(fifoDir,"fromR.fifo")
   dir = getwd()
   cat("SwiftRServer starting in dir:",dir,"\n");
   repeat {
@@ -45,6 +47,14 @@
   }
 }
 
+doFail <- function( error )
+{
+  outFifoName = file.path(fifoDir,"fromR.fifo")
+  outfifo <- fifo(outFifoName,open="wb",blocking=TRUE)
+  cat(file=outfifo, paste("ERROR: R server failed with error", gsub("\n", " ", error)))
+  close(outfifo)
+}
+
 doInit <- function(initializer, env) {
   #print(sprintf("received initializer=%s latestInitializer=%s\n",
   #                         initializer, latestInitializer));
@@ -174,5 +184,5 @@
 
 cat("calling server: dir=",fifoDir,"\n")
 setwd(fifoDir)
-SwiftRFifoServer(fifoDir)
-cat("returned from server: dir=",fifoDir,"\n")
+tryCatch(SwiftRFifoServer(fifoDir), error=
+        cat("returned from server: dir=",fifoDir,"\n"))




More information about the Swift-commit mailing list