This is an automated email from the ASF dual-hosted git repository. zjffdu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new a2a6215 IPythonInterpreter delete temp file and close stream a2a6215 is described below commit a2a621595afcc65e965382d5a0412ade0e299610 Author: yx91490 <yx91...@126.com> AuthorDate: Tue Jan 22 13:47:38 2019 +0800 IPythonInterpreter delete temp file and close stream ### What is this PR for? delete temporary file and close inputstream in IPythonInterpreter.checkIPythonPrerequisite() ### What type of PR is it? [Bug Fix] ### Todos *no ### What is the Jira issue? * https://jira.apache.org/jira/browse/ZEPPELIN-3910, [ZEPPELIN-3910] ### How should this be tested? * manual. ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: yx91490 <yx91...@126.com> Closes #3287 from yx91490/ipy_tmp_file and squashes the following commits: c811e3736 [yx91490] delete temp file and close stream --- .../apache/zeppelin/python/IPythonInterpreter.java | 48 +++++++++++++--------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java b/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java index 3c646ae..b357e88 100644 --- a/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java +++ b/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java @@ -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)); - } - 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); + } } - 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 ""; }