Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug where logs do not properly get updated in significant size simulations. #1394

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion vcell-cli/src/main/java/org/vcell/cli/CLIPythonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CLIPythonManager {
private static final String PYTHON_EXE_NAME = OperatingSystemInfo.getInstance().isWindows() ? "python" : "python3";

private static CLIPythonManager instance = null;
private static final int DEFAULT_TIMEOUT = 7000; // was 600 seconds (10 minutes), now 5 seconds
private static final int DEFAULT_TIMEOUT = 15000; // was 600 seconds (10 minutes), now 15 seconds

private static final boolean USE_SHARED_SHELL = true;

Expand Down Expand Up @@ -101,6 +101,9 @@ public void closePythonProcess() throws IOException {
// Exit the living Python Process
lg.debug("Closing Python Instance");
if (this.pythonOSW != null && this.pythonISB != null) this.sendNewCommand("exit()"); // Sends kill command ("exit()") to python.exe instance;
try {
for (int i = 1; i <= 5; i++) if (this.pythonProcess != null && this.pythonProcess.isAlive()) Thread.sleep(1000 * i);
} catch (InterruptedException ignored) {} // Just want to try and give the process a chance to close gracefully
if (this.pythonProcess != null && this.pythonProcess.isAlive()) this.pythonProcess.destroyForcibly(); // Making sure it's quite dead

// Making sure we clean up
Expand Down Expand Up @@ -191,6 +194,16 @@ private String callPython(String command) throws PythonStreamException, TimeoutE
}
} catch (IOException | InterruptedException e4){
throw new PythonStreamException("Python process encountered an exception:\n" + e4.getMessage(), e4);
} finally { // Let's make sure our buffer isn't clogged; for now, we'll log, but discard any extra output
StringBuilder remainder = new StringBuilder("Leftovers in buffer: \n");
try {
while (this.pythonISB.ready()){
remainder.append(this.getResultsOfLastCommand()).append("\n");
}
} catch (IOException | InterruptedException cleaningException){
lg.warn("Received exception while trying to clear buffer:", cleaningException);
}
lg.debug(remainder.toString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Integer call() {
try {
CLIPythonManager.getInstance().instantiatePythonProcess();
ExecuteImpl.singleMode(ARCHIVE, tmpDir, cliRecorder, true);
FileUtils.copyDirectoryContents(tmpDir, OUT_DIR, true, null);
CLIPythonManager.getInstance().closePythonProcess(); // Give the process time to finish
if (!Tracer.hasErrors()) return 0;
if (!bQuiet) {
logger.error("Errors occurred during execution");
Expand All @@ -110,6 +110,7 @@ public Integer call() {
logger.error(e.getMessage(), e);
}
logger.debug("Finished all execution.");
FileUtils.copyDirectoryContents(tmpDir, OUT_DIR, true, null);
}
} catch (Exception e) {
if (!bQuiet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ public Integer call() {
bEncapsulateOutput, bSmallMeshOverride);
}
}
FileUtils.copyDirectoryContents(tmpDir, outputFilePath, true, null);
CLIPythonManager.getInstance().closePythonProcess();
// WARNING: Python needs re-instantiation once the above line is called!
FileUtils.copyDirectoryContents(tmpDir, outputFilePath, true, null);
return 0;
} catch (Exception e) { ///TODO: Break apart into specific exceptions to maximize logging.
org.apache.logging.log4j.LogManager.getLogger(this.getClass()).error(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public void postProcessessArchive() throws InterruptedException, PythonStreamExc

}
PythonCalls.setOutputMessage("null", "null", outputDir, "omex", logOmexMessage.toString());

logger.debug("Finished Execution of Archive: " + bioModelBaseName);
}

Expand Down
12 changes: 3 additions & 9 deletions vcell-cli/src/main/java/org/vcell/cli/run/PythonCalls.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,16 @@ public static void genPlotsPseudoSedml(String sedmlPath, String resultOutDir) th
CLIPythonManager cliPythonManager = CLIPythonManager.getInstance();
String results = cliPythonManager.callPython("genPlotsPseudoSedml", sedmlPath, resultOutDir);
cliPythonManager.parsePythonReturn(results);
/**
* replace with the following once the leak is fixed
*/
// CLIPythonManager cliPythonManager = CLIPythonManager.getInstance();
// String results = cliPythonManager.callPython("genPlotsPseudoSedml", sedmlPath, resultOutDir);
// cliPythonManager.printPythonErrors(results);
}

private static String stripIllegalChars(String s){
String fStr = "";
StringBuilder fStr = new StringBuilder();
for (char c : s.toCharArray()){
char cAppend = ((int)c) < 16 ? ' ' : c;
if (cAppend == '"')
cAppend = '\'';
fStr += cAppend;
fStr.append(cAppend);
}
return fStr;
return fStr.toString();
}
}