Github user zjffdu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13599#discussion_r79328285
  
    --- Diff: 
core/src/main/scala/org/apache/spark/api/python/PythonWorkerFactory.scala ---
    @@ -69,6 +84,67 @@ private[spark] class PythonWorkerFactory(pythonExec: 
String, envVars: Map[String
       }
     
       /**
    +   * Create virtualenv using native virtualenv or conda
    +   *
    +   * Native Virtualenv:
    +   *   -  Execute command: virtualenv -p pythonExec --no-site-packages 
virtualenvName
    +   *   -  Execute command: python -m pip --cache-dir cache-dir install -r 
requirement_file
    +   *
    +   * Conda
    +   *   -  Execute command: conda create --prefix prefix --file 
requirement_file -y
    +   *
    +   */
    +  def setupVirtualEnv(): Unit = {
    +    logDebug("Start to setup virtualenv...")
    +    logDebug("user.dir=" + System.getProperty("user.dir"))
    +    logDebug("user.home=" + System.getProperty("user.home"))
    +
    +    require(virtualEnvType == "native" || virtualEnvType == "conda",
    +      s"VirtualEnvType: ${virtualEnvType} is not supported" )
    +    virtualEnvName = "virtualenv_" + conf.getAppId + "_" + 
VIRTUALENV_ID.getAndIncrement()
    +    // use the absolute path when it is local mode otherwise just use 
filename as it would be
    +    // fetched from FileServer
    +    val pyspark_requirements =
    +      if (Utils.isLocalMaster(conf)) {
    +        conf.get("spark.pyspark.virtualenv.requirements")
    +      } else {
    +        conf.get("spark.pyspark.virtualenv.requirements").split("/").last
    +      }
    +
    +    val createEnvCommand =
    +      if (virtualEnvType == "native") {
    +        Arrays.asList(virtualEnvPath,
    +          "-p", pythonExec,
    +          "--no-site-packages", virtualEnvName)
    +      } else {
    +        Arrays.asList(virtualEnvPath,
    +          "create", "--prefix", System.getProperty("user.dir") + "/" + 
virtualEnvName,
    +          "--file", pyspark_requirements, "-y")
    +      }
    +    execCommand(createEnvCommand)
    +    // virtualenv will be created in the working directory of Executor.
    +    virtualPythonExec = virtualEnvName + "/bin/python"
    +    if (virtualEnvType == "native") {
    +      execCommand(Arrays.asList(virtualPythonExec, "-m", "pip",
    +        "--cache-dir", System.getProperty("user.home"),
    +        "install", "-r", pyspark_requirements))
    +    }
    +  }
    +
    +  def execCommand(commands: java.util.List[String]): Unit = {
    +    logDebug("Running command:" + commands.asScala.mkString(" "))
    +    val pb = new ProcessBuilder(commands).inheritIO()
    --- End diff --
    
    It is for redirect the process output to executor output in case anything 
wrong when setting up the virtualenv.  Otherwise it is difficult to know what's 
wrong. I think it is acceptable to redirect output by default. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to