 +          self.synchronized {
 +            simpleWorkers.put(socket, worker)
 +          }
-+          println(s"Thread ${Thread.currentThread().getId}: creating simple worker finished")
++          logInfo(s"Thread ${Thread.currentThread().getId}: creating simple worker finished")
 +          return socket
 +        } catch {
 +          case e: Exception =>
 +            throw new SparkException("Python worker failed to connect back.", e)
-+        }
-+      }
-+    } finally {
-+      if (serverSocket != null) {
-+        serverSocket.close()
-+      }
+         }
+-        return socket
+-      } catch {
+-        case e: Exception =>
+-          throw new SparkException("Python worker failed to connect back.", e)
+       }
+     } finally {
+       if (serverSocket != null) {
+         serverSocket.close()
+       }
      }
 +
      null
    }
 
-@@ -378,7 +467,17 @@ private[spark] class PythonWorkerFactory(pythonExec: String, envVars: Map[String
+@@ -378,7 +450,17 @@ private[spark] class PythonWorkerFactory(pythonExec: String, envVars: Map[String
    }
  }
 


 private[spark] object BarrierTaskContextMessageProtocol {
diff --git a/core/src/main/scala/org/apache/spark/api/python/PythonWorkerFactory.scala b/core/src/main/scala/org/apache/spark/api/python/PythonWorkerFactory.scala
index df236ba892..dd3fde3040 100644
--- a/core/src/main/scala/org/apache/spark/api/python/PythonWorkerFactory.scala
+++ b/core/src/main/scala/org/apache/spark/api/python/PythonWorkerFactory.scala
@@ -17,7 +17,7 @@

+            }
+            val ss = new ServerSocket(0, 1, InetAddress.getByAddress(Array(127, 0, 0, 1)))
+            ss.setSoTimeout(10000)
+            logInfo(s"scala2: new data local port ${ss.getLocalPort}--------")
+            val output = new DataOutputStream(
+              new BufferedOutputStream(manageSocket.getOutputStream, 1024))
+            output.writeInt(ss.getLocalPort)
