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

IPythonInterpreter delete temp file and close stream #3287

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -161,38 +161,46 @@ public void open() throws InterpreterException {
*/
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));
}
String freezeOutput = IOUtils.toString(new FileInputStream(stdoutFile));
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";
try (FileInputStream in = new FileInputStream(stderrFile)) {
return "Fail to run pip freeze.\n" + IOUtils.toString(in);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it going to close FileInputStream when it is out of scope here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

}
if (!freezeOutput.contains("protobuf=")) {
return "protobuf 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");
}
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 "";
}
Expand Down