delete temp file and close stream

This commit is contained in:
yx91490 2019-01-22 13:47:38 +08:00
parent 2b4920c974
commit c811e3736a

View file

@ -161,38 +161,46 @@ public class IPythonInterpreter extends Interpreter implements ExecuteResultHand
*/
public String checkIPythonPrerequisite(String pythonExec) {
ProcessBuilder processBuilder = new ProcessBuilder(pythonExec, "-m", "pip", "freeze");
File stderrFile = null;
File stdoutFile = null;
try {
File stderrFile = File.createTempFile("zeppelin", ".txt");
stderrFile = File.createTempFile("zeppelin", ".txt");
processBuilder.redirectError(stderrFile);
File stdoutFile = File.createTempFile("zeppelin", ".txt");
stdoutFile = File.createTempFile("zeppelin", ".txt");
processBuilder.redirectOutput(stdoutFile);
Process proc = processBuilder.start();
int ret = proc.waitFor();
if (ret != 0) {
return "Fail to run pip freeze.\n" +
IOUtils.toString(new FileInputStream(stderrFile));
try (FileInputStream in = new FileInputStream(stderrFile)) {
return "Fail to run pip freeze.\n" + IOUtils.toString(in);
}
}
String freezeOutput = IOUtils.toString(new FileInputStream(stdoutFile));
if (!freezeOutput.contains("jupyter-client=")) {
return "jupyter-client is not installed.";
try (FileInputStream in = new FileInputStream(stdoutFile)) {
String freezeOutput = IOUtils.toString(in);
if (!freezeOutput.contains("jupyter-client=")) {
return "jupyter-client is not installed.";
}
if (!freezeOutput.contains("ipykernel=")) {
return "ipykernel is not installed";
}
if (!freezeOutput.contains("ipython=")) {
return "ipython is not installed";
}
if (!freezeOutput.contains("grpcio=")) {
return "grpcio is not installed";
}
if (!freezeOutput.contains("protobuf=")) {
return "protobuf is not installed";
}
LOGGER.info("IPython prerequisite is met");
}
if (!freezeOutput.contains("ipykernel=")) {
return "ipykernel is not installed";
}
if (!freezeOutput.contains("ipython=")) {
return "ipython is not installed";
}
if (!freezeOutput.contains("grpcio=")) {
return "grpcio is not installed";
}
if (!freezeOutput.contains("protobuf=")) {
return "protobuf is not installed";
}
LOGGER.info("IPython prerequisite is met");
} catch (Exception e) {
LOGGER.warn("Fail to checkIPythonPrerequisite", e);
return "Fail to checkIPythonPrerequisite: " + ExceptionUtils.getStackTrace(e);
} finally {
FileUtils.deleteQuietly(stderrFile);
FileUtils.deleteQuietly(stdoutFile);
}
return "";
}