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 89a7723  [ZEPPELIN-4666]. IPySparkInterpreter is opened twice
89a7723 is described below

commit 89a772331b6fac6586095a4b711acaf3601e71c3
Author: Jeff Zhang <zjf...@apache.org>
AuthorDate: Thu Mar 5 14:24:35 2020 +0800

    [ZEPPELIN-4666]. IPySparkInterpreter is opened twice
    
    ### What is this PR for?
    
    This bug happens when ipython is available. Then IPythonInterpreter will be 
opened twice, one by `%spark.python`, another by `%spark.ipyspark`.  This PR 
add one field `opened` to indicate whether it is opened already.
    
    ### What type of PR is it?
    [Bug Fix ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-4666
    
    ### How should this be tested?
    * Manually tested
    
    ### 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: Jeff Zhang <zjf...@apache.org>
    
    Closes #3679 from zjffdu/ZEPPELIN-4666 and squashes the following commits:
    
    0309a03e5 [Jeff Zhang] [ZEPPELIN-4666]. IPySparkInterpreter is opened twice
---
 .../org/apache/zeppelin/spark/IPySparkInterpreter.java   | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git 
a/spark/interpreter/src/main/java/org/apache/zeppelin/spark/IPySparkInterpreter.java
 
b/spark/interpreter/src/main/java/org/apache/zeppelin/spark/IPySparkInterpreter.java
index 6345315..6436d92 100644
--- 
a/spark/interpreter/src/main/java/org/apache/zeppelin/spark/IPySparkInterpreter.java
+++ 
b/spark/interpreter/src/main/java/org/apache/zeppelin/spark/IPySparkInterpreter.java
@@ -39,31 +39,37 @@ public class IPySparkInterpreter extends IPythonInterpreter 
{
   private static final Logger LOGGER = 
LoggerFactory.getLogger(IPySparkInterpreter.class);
 
   private SparkInterpreter sparkInterpreter;
+  private boolean opened = false;
 
   public IPySparkInterpreter(Properties property) {
     super(property);
   }
 
   @Override
-  public void open() throws InterpreterException {
+  public synchronized void open() throws InterpreterException {
+    // IPySparkInterpreter may already be opened in PySparkInterpreter when 
ipython is available.
+    if (opened) {
+      return;
+    }
     PySparkInterpreter pySparkInterpreter =
-        getInterpreterInTheSameSessionByClassName(PySparkInterpreter.class, 
false);
+            
getInterpreterInTheSameSessionByClassName(PySparkInterpreter.class, false);
     setProperty("zeppelin.python", pySparkInterpreter.getPythonExec());
     sparkInterpreter = 
getInterpreterInTheSameSessionByClassName(SparkInterpreter.class);
     setProperty("zeppelin.py4j.useAuth",
-        sparkInterpreter.getSparkVersion().isSecretSocketSupported() + "");
+            sparkInterpreter.getSparkVersion().isSecretSocketSupported() + "");
     SparkConf conf = sparkInterpreter.getSparkContext().getConf();
     // only set PYTHONPATH in embedded, local or yarn-client mode.
     // yarn-cluster will setup PYTHONPATH automatically.
     if (!conf.contains("spark.submit.deployMode") ||
-        !conf.get("spark.submit.deployMode").equals("cluster")) {
+            !conf.get("spark.submit.deployMode").equals("cluster")) {
       setAdditionalPythonPath(PythonUtils.sparkPythonPath());
     }
     setUseBuiltinPy4j(false);
     setAdditionalPythonInitFile("python/zeppelin_ipyspark.py");
     setProperty("zeppelin.py4j.useAuth",
-        sparkInterpreter.getSparkVersion().isSecretSocketSupported() + "");
+            sparkInterpreter.getSparkVersion().isSecretSocketSupported() + "");
     super.open();
+    opened = true;
   }
 
   @Override

Reply via email to