spark-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JoshRosen <...@git.apache.org>
Subject [GitHub] spark pull request: SPARK-1004. PySpark on YARN
Date Sat, 08 Mar 2014 20:17:34 GMT
Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/30#discussion_r10410971
  
    --- Diff: python/pyspark/java_gateway.py ---
    @@ -66,3 +71,30 @@ def run(self):
         java_import(gateway.jvm, "org.apache.spark.mllib.api.python.*")
         java_import(gateway.jvm, "scala.Tuple2")
         return gateway
    +
    +def set_env_vars_for_yarn(pyspark_zip):
    +    if "SPARK_YARN_DIST_FILES" in os.environ:
    +        os.environ["SPARK_YARN_DIST_FILES"] += ("," + pyspark_zip)
    +    else:
    +        os.environ["SPARK_YARN_DIST_FILES"] = pyspark_zip
    +    
    +    # Add the pyspark zip to the python path
    +    env_map = parse_env(os.environ.get("SPARK_YARN_USER_ENV", ""))
    +    if "PYTHONPATH" in env_map:
    +        env_map["PYTHONPATH"] += (":" + os.path.basename(pyspark_zip))
    +    else:
    +        env_map["PYTHONPATH"] = os.path.basename(pyspark_zip)
    +
    +    os.environ["SPARK_YARN_USER_ENV"] = ",".join(map(lambda v: v[0] + "=" + v[1],
    +        env_map.items()))
    +
    +def parse_env(env_str):
    +    # Turns a comma-separated of env settings into a dict that maps env vars to
    +    # their values.
    +    env = {}
    +    for var_str in env_str.split(","):
    +        parts = var_str.split("=")
    +        if len(parts) == 2:
    --- End diff --
    
    Do you think it would be worth it to crash or throw an error when passed an invalid env
string?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message