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

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Feb 9 16:09:06 CST 2011


Author: tga
Date: 2011-02-09 16:09:06 -0600 (Wed, 09 Feb 2011)
New Revision: 4076

Modified:
   SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh
   SwiftApps/SwiftR/Swift/exec/SwiftRServer.R
Log:
modified so that failure running R batch would result in an error message correctly being sent down the pipe

Modified: SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh
===================================================================
--- SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh	2011-02-09 21:13:56 UTC (rev 4075)
+++ SwiftApps/SwiftR/Swift/exec/EvalRBatchPersistent.sh	2011-02-09 22:09:06 UTC (rev 4076)
@@ -50,12 +50,14 @@
   fi
 }
 
+
 trap "onexit 1" 1
 trap "onexit 2" 2
 trap "onexit 3" 3
 trap "onexit 15" 15
 trap "onexit EXIT" EXIT
 
+
 function idletimer {
   cd $1
   while true; do
@@ -92,9 +94,10 @@
   mkfifo $SLOTDIR/fromR.fifo
   chmod +x $RServerScript
   echo "$0: INFO: Launching $RServerScript $SLOTDIR"
-  PATH=.:$PATH 
+  PATH=.:$PATH
   #echo PATH: $PATH > $SLOTDIR/R.log
   #which Rscript >> $SLOTDIR/R.log
+  echo $PATH
   $RServerScript $SLOTDIR >> $SLOTDIR/R.log 2>&1 &   # 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"
@@ -122,26 +125,31 @@
 done
 echo DB: Obtained $SLOTDIR/mutex
 
-echo run $(pwd)/$callFile $(pwd)/$resultFile > $SLOTDIR/toR.fifo
-touch $SLOTDIR/lastwrite
+if echo run $(pwd)/$callFile $(pwd)/$resultFile > $SLOTDIR/toR.fifo
+then
+    touch $SLOTDIR/lastwrite
 
-echo DB: Sent request
+    echo DB: Sent request
 
-echo dummy stderr response 1>&2 # FIXME - testing if this is the provider staging problem (not xfering zero len stderr)
+    echo dummy stderr response 1>&2 # FIXME - testing if this is the provider staging problem (not xfering zero len stderr)
 
-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
+    res=$(cat < $SLOTDIR/fromR.fifo)
+    echo DB: Got response: $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
 
-rmdir $SLOTDIR/mutex
+    echo DB: Freed $SLOTDIR/mutex
+else
+    echo "ERROR: Could not write to fifo ok"
+    rmdir $SLOTDIR/mutex
 
-echo DB: Freed $SLOTDIR/mutex
+    exit 1
+fi
 
 # Fixme: how to get exceptions and stdout/stderr text from R server ???

Modified: SwiftApps/SwiftR/Swift/exec/SwiftRServer.R
===================================================================
--- SwiftApps/SwiftR/Swift/exec/SwiftRServer.R	2011-02-09 21:13:56 UTC (rev 4075)
+++ SwiftApps/SwiftR/Swift/exec/SwiftRServer.R	2011-02-09 22:09:06 UTC (rev 4076)
@@ -21,24 +21,25 @@
     cat("SwiftRServer at top of loop is in dir:",getwd(),"\n");
     setwd(dir) # FIXME: not yet sure what is changing the CWD
     infifo <- fifo(inFifoName,open="rb",blocking=TRUE)
-    outfifo <- fifo(outFifoName,open="wb",blocking=TRUE)
     cmd <- scan(infifo,what=list("","",""),nlines=1,flush=FALSE,quiet=FALSE,fill=TRUE)
     op = cmd[[1]]
     callBatchFileName = cmd[[2]]
     resultBatchFileName = cmd[[3]]
     cat("cmd: op=",op," call batch=",callBatchFileName," result batch=",resultBatchFileName,"\n");
-    cat(file=outfifo, "Read from sock: cmd=",cmd[[1]], cmd[[2]],"\n");
+    #cat(file=outfifo, "Read from sock: cmd=",cmd[[1]], cmd[[2]],"\n");
     if(is.null(op)) {
       cat("op is NULL\n")
     }
     else {
       if( identical(op,"quit")) {
+        outfifo <- fifo(outFifoName,open="wb",blocking=TRUE)
         cat(file=outfifo,"Server closing down.\n")
         break
       }
       if( identical(op,"run")) {
-        cat(file=outfifo, "About to run batch file: ", callBatchFileName,"\n");
+        #cat(file=outfifo, "About to run batch file: ", callBatchFileName,"\n");
         runBatch(callBatchFileName,resultBatchFileName)
+        outfifo <- fifo(outFifoName,open="wb",blocking=TRUE)
         cat(file=outfifo, "Batch completed: result batch file: ", resultBatchFileName,"\n");
       }
     }
@@ -184,5 +185,5 @@
 
 cat("calling server: dir=",fifoDir,"\n")
 setwd(fifoDir)
-tryCatch(SwiftRFifoServer(fifoDir), error=
-        cat("returned from server: dir=",fifoDir,"\n"))
+tryCatch(SwiftRFifoServer(fifoDir), error=doFail)
+cat("returned from server: dir=",fifoDir,"\n"))




More information about the Swift-commit mailing list