[Swift-commit] r4000 - in SwiftApps/SwiftR/Swift: R exec

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Jan 19 16:30:37 CST 2011


Author: tga
Date: 2011-01-19 16:30:37 -0600 (Wed, 19 Jan 2011)
New Revision: 4000

Added:
   SwiftApps/SwiftR/Swift/exec/killtree
Modified:
   SwiftApps/SwiftR/Swift/R/Swift.R
   SwiftApps/SwiftR/Swift/R/Workers.R
   SwiftApps/SwiftR/Swift/exec/start-swift
   SwiftApps/SwiftR/Swift/exec/start-swift-daemon
Log:
Several improvements:
* R now correctly sends signals to the appropriate worker processes when the session exists
* worker processes remove their request pipes when they quit
* if you run a swiftapply, the R code now checks whether a valid request pipe exists and can detect that nothing is running.


Modified: SwiftApps/SwiftR/Swift/R/Swift.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Swift.R	2011-01-19 19:32:47 UTC (rev 3999)
+++ SwiftApps/SwiftR/Swift/R/Swift.R	2011-01-19 22:30:37 UTC (rev 4000)
@@ -127,16 +127,22 @@
 
     requestPipeName=paste(swiftServerDir,"/requestpipe",sep="")
     resultPipeName=paste(swiftServerDir,"/resultpipe",sep="")
+    if (file.exists(requestPipeName)) {
+        requestPipe <- fifo(requestPipeName,open="w",blocking=TRUE)
+        cat(file=requestPipe,paste(reqdir,"\n",sep=""))
+        close(requestPipe)
 
-    requestPipe <- fifo(requestPipeName,open="w",blocking=TRUE)
-    cat(file=requestPipe,paste(reqdir,"\n",sep=""))
-    close(requestPipe)
+        # Wait for reply from service
 
-    # Wait for reply from service
-
-    resultPipe <- fifo(resultPipeName,open="r",blocking=TRUE)
-    resultStatus <- readLines(con=resultPipe,n=1,ok=TRUE)
-    close(resultPipe)
+        resultPipe <- fifo(resultPipeName,open="r",blocking=TRUE)
+        resultStatus <- readLines(con=resultPipe,n=1,ok=TRUE)
+        close(resultPipe)
+    }
+    else {
+        stop(paste("It appears no SwiftR servers of type", swiftserver, 
+                "are running, as no request pipe exists in", 
+                swiftServerDir,"exists"))
+    }
   }
 
   # Fetch the batch results

Modified: SwiftApps/SwiftR/Swift/R/Workers.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Workers.R	2011-01-19 19:32:47 UTC (rev 3999)
+++ SwiftApps/SwiftR/Swift/R/Workers.R	2011-01-19 22:30:37 UTC (rev 4000)
@@ -93,9 +93,8 @@
     cat("Shutting down Swift worker processes\n")
     # shut down all worker processes using kill
     for (pid in .swift.workers) {
-        cat("Killing ", pid, "\n")
-        killCmd <- paste("kill","-1", pid, " &> /dev/null")
-        cat(killCmd, "\n")
+        cmdString <- file.path(.find.package("Swift"), "exec/killtree")
+        killCmd <- paste(cmdString,pid)
         system(killCmd, wait=FALSE)
     }
 

Added: SwiftApps/SwiftR/Swift/exec/killtree
===================================================================
--- SwiftApps/SwiftR/Swift/exec/killtree	                        (rev 0)
+++ SwiftApps/SwiftR/Swift/exec/killtree	2011-01-19 22:30:37 UTC (rev 4000)
@@ -0,0 +1,19 @@
+#!/bin/sh
+tokill=$1
+echo $tokill
+while [ ! -z $tokill ]
+do
+    children=""
+    for pid in $tokill
+    do
+        #echo $pid
+        newkids=`ps h -o pid --ppid $pid`
+        if [ ! -z $newkids ]
+        then
+            children="$children $newkids"
+        fi 
+        #echo kids $children
+        kill $pid
+    done
+    tokill=$children
+done


Property changes on: SwiftApps/SwiftR/Swift/exec/killtree
___________________________________________________________________
Name: svn:executable
   + *

Modified: SwiftApps/SwiftR/Swift/exec/start-swift
===================================================================
--- SwiftApps/SwiftR/Swift/exec/start-swift	2011-01-19 19:32:47 UTC (rev 3999)
+++ SwiftApps/SwiftR/Swift/exec/start-swift	2011-01-19 22:30:37 UTC (rev 4000)
@@ -1,6 +1,6 @@
 #! /bin/bash
 
-# set -x
+#set -x
 
 export TRAPEVENTS="EXIT 1 2 3 15"  # Signals and conditions to trap
 
@@ -370,6 +370,15 @@
 out=swift.stdouterr
 touch $out
 
+
+# Reset signal handling behaviour to default:
+# sending a HUP to this process should then trigger termination
+# of all subprocess unless we change it by hand.  This is added
+# here to work around problems where parent processes had changed
+# signal handlers
+#trap " echo quitting; exit 0 " $TRAPEVENTS
+
+
 if [ $server = local ]; then
 
   if [ $cores -eq 0 ]; then
@@ -379,7 +388,18 @@
 
 
   source $SWIFTRBIN/configure-server-local $cores
+  function onexit {
+    # don't accept any more requests: unlink fifo from filesystem
+    if [ -p requestpipe ]; then
+        rm requestpipe 
+    fi
+    exit 0
+  }
 
+  TRAPEVENTS="EXIT 1 2 3 15"  # Signals and conditions to trap
+  trap onexit $TRAPEVENTS
+
+
 elif [ $server = ssh ]; then
 
   if [ $cores -eq 0 ]; then
@@ -394,6 +414,10 @@
   TRAPEVENTS="EXIT 1 2 3 15"  # Signals and conditions to trap
 
   function onexit {
+    # don't accept any more requests: unlink fifo from filesystem
+    if [ -p requestpipe ]; then
+        rm requestpipe 
+    fi
     coasterservicepid="" # null: saved in case we go back to using coaster servers
     trap - $TRAPEVENTS
     sshpids=$(cat $sshpidfile)
@@ -429,6 +453,10 @@
   TRAPEVENTS="EXIT 1 2 3 15"  # Signals and conditions to trap
 
   function onexit {
+    # don't accept any more requests: unlink fifo from filesystem
+    if [ -p requestpipe ]; then
+        rm requestpipe 
+    fi
     coasterservicepid="" # null: saved in case we go back to using coaster servers
     trap - $TRAPEVENTS
     jobid=$(cat $jobidfile)

Modified: SwiftApps/SwiftR/Swift/exec/start-swift-daemon
===================================================================
--- SwiftApps/SwiftR/Swift/exec/start-swift-daemon	2011-01-19 19:32:47 UTC (rev 3999)
+++ SwiftApps/SwiftR/Swift/exec/start-swift-daemon	2011-01-19 22:30:37 UTC (rev 4000)
@@ -7,8 +7,14 @@
 # and then, as the only thing written to stdout, echoes
 # the pid of start-swift
 ssscript=`dirname $0`/start-swift
+
 # Start as detached daemon, with output going to stdout
+
+
+# Start up a subprocess with a new process group
+# childpid will be of form '[jobno] pid'
 $ssscript "$@" 1>&2 &
 childpid=$!
+
+
 echo ${childpid}
-disown $childpid




More information about the Swift-commit mailing list