[chronojump] encoderRProc checks if processes are responsive
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] encoderRProc checks if processes are responsive
- Date: Mon, 3 Aug 2015 11:00:31 +0000 (UTC)
commit 4c602a19030fe4af15d3e0e184568b75bc844eca
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Aug 3 12:59:11 2015 +0200
encoderRProc checks if processes are responsive
encoder/call_graph.R | 13 +++++++++++
encoder/capture.R | 10 ++++++++-
encoder/graph.R | 4 +++
src/encoderRProc.cs | 56 +++++++++++++++++++++++++++++++++++++++++++++++--
4 files changed, 79 insertions(+), 4 deletions(-)
---
diff --git a/encoder/call_graph.R b/encoder/call_graph.R
index 7779edd..dff5283 100644
--- a/encoder/call_graph.R
+++ b/encoder/call_graph.R
@@ -76,5 +76,18 @@ while(TRUE) {
quit("no")
write("call_graph.R received a continue signal", stderr())
+
+ #answer the ping
+ #eg. input = 'PINGC:/Temp.../1234.txt'
+
+ input=substring(input,5,) #input = 'C:/Temp.../1234.txt'
+ file.create(input)
+ print(paste(input, "created from call_graph.R"))
+ write("created from call_graph.R", stderr())
+
+ #Wait to the Continue "C"
+ #Needed to prepare outputFileCheck files
+ input <- readLines(f, n = 1L)
+
options <- scan(optionsFile, comment.char="#", what=character(), sep="\n")
}
diff --git a/encoder/capture.R b/encoder/capture.R
index 3be5434..493cd05 100644
--- a/encoder/capture.R
+++ b/encoder/capture.R
@@ -140,8 +140,16 @@ doProcess <- function(options)
#if should continue with another capture
#then read options again
- while(input[1] == "C") {
+ while(substring(input,1,4) == "PING") {
write("capture.R received a continue signal", stderr())
+
+ #answer the ping
+ #eg. input = 'PINGC:/Temp.../1234.txt'
+
+ input=substring(input,5,) #input = 'C:/Temp.../1234.txt'
+ file.create(input)
+ print(paste(input, "created from capture.R"))
+ write("created from capture.R", stderr())
options <- scan(optionsFile, comment.char="#", what=character(), sep="\n")
op <- assignOptions(options)
diff --git a/encoder/graph.R b/encoder/graph.R
index 564445d..07d90a1 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -2519,6 +2519,9 @@ doProcess <- function(options)
}
}
+
+ write("starting analysis...", stderr())
+
#make some check here, because this file is being readed in chronojump
#write(paste("(4/5)",translate("Repetitions processed")), op$OutputData2)
@@ -3084,6 +3087,7 @@ doProcess <- function(options)
print("Creating (op$OutputData2)5.txt with touch method...")
file.create(paste(op$OutputData2,"5.txt",sep=""))
print("Created")
+ write("created ...5.txt", stderr())
warnings()
}
diff --git a/src/encoderRProc.cs b/src/encoderRProc.cs
index edc6ed2..7db56b5 100644
--- a/src/encoderRProc.cs
+++ b/src/encoderRProc.cs
@@ -45,7 +45,7 @@ public abstract class EncoderRProc
bool ok = true;
- if(isRunning()) {
+ if(isRunning() && isResponsive(p)) {
LogB.Debug("calling continue");
ok = continueProcess();
} else {
@@ -96,7 +96,6 @@ public abstract class EncoderRProc
return true;
}
-
/*
* don't use this because in linux R script can be called by:
* "/usr/lib/R/bin/exec/R"
@@ -113,6 +112,50 @@ public abstract class EncoderRProc
return false;
}
*/
+
+ /*
+ * The process.Responding only works on GUI processes
+ * So, here we send a "ping" expecting to see the result in short time
+ *
+ * TODO: maybe is good to kill the unresponsive processes
+ */
+ private bool isResponsive(Process process)
+ {
+ Random rnd = new Random();
+ int randomInt = rnd.Next(); //eg. 1234
+
+ string randomPingStr = "PING" + Path.Combine(Path.GetTempPath(), "chronojump" +
randomInt.ToString() + ".txt");
+ //eg Linux: 'PING/tmp/chronojump1234.txt'
+ //eg Windows: 'PINGC:\Temp...\chronojump1234.txt'
+
+ if (UtilAll.IsWindows()) {
+ //On win32 R understands backlash as an escape character and
+ //a file path uses Unix-like path separator '/'
+ randomPingStr = randomPingStr.Replace("\\","/");
+ }
+ //eg Windows: 'PINGC:/Temp.../chronojump1234.txt'
+
+ LogB.Information("Sending ping: " + randomPingStr);
+ try {
+ process.StandardInput.WriteLine(randomPingStr);
+ } catch {
+ LogB.Warning("Catched waiting response");
+ return false;
+ }
+
+ //wait 250ms the response
+ System.Threading.Thread.Sleep(250);
+
+ //On Linux will be '/' on Windows '\'
+ if(File.Exists(Path.Combine(Path.GetTempPath(), "chronojump" + randomInt.ToString() +
".txt"))) {
+ LogB.Information("Process is responding");
+ return true;
+ }
+
+ LogB.Warning("Process is NOT responding");
+ return false;
+ }
+
protected virtual void writeOptionsFile()
{
@@ -121,9 +164,10 @@ public abstract class EncoderRProc
protected virtual bool startProcess() {
return true;
}
-
+
protected virtual bool continueProcess()
{
+ /*
LogB.Debug("sending continue process");
//try/catch because sometimes the stdin write gots broken
try {
@@ -132,6 +176,12 @@ public abstract class EncoderRProc
LogB.Debug("calling start because continue process was problematic");
return startProcess();
}
+ */
+
+ //1.5.3 has the isResponding call.
+ //in capture, if answers it starts automatically. Don't send a "C"
+ //in graph is different because we need to prepare the outputFileCheck files. So there "C" is
needed
+ LogB.Debug("continuing process");
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]