You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zeppelin.apache.org by GitBox <gi...@apache.org> on 2019/01/24 03:47:32 UTC

[GitHub] felixcheung commented on a change in pull request #3287: IPythonInterpreter delete temp file and close stream

felixcheung commented on a change in pull request #3287: IPythonInterpreter delete temp file and close stream
URL: https://github.com/apache/zeppelin/pull/3287#discussion_r250457908
 
 

 ##########
 File path: python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java
 ##########
 @@ -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);
+        }
 
 Review comment:
   is it going to close FileInputStream when it is out of scope here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services