Github user BryanCutler commented on a diff in the pull request:
https://github.com/apache/spark/pull/14959#discussion_r80599035
--- Diff: python/pyspark/conf.py ---
@@ -101,13 +101,25 @@ def __init__(self, loadDefaults=True, _jvm=None,
_jconf=None):
self._jconf = _jconf
else:
from pyspark.context import SparkContext
- SparkContext._ensure_initialized()
_jvm = _jvm or SparkContext._jvm
- self._jconf = _jvm.SparkConf(loadDefaults)
+
+ if _jvm:
+ # JVM is created, so create self._jconf directly through
JVM
+ self._jconf = _jvm.SparkConf(loadDefaults)
+ self._conf = None
+ else:
+ # JVM is not created, so store data in self._conf first
+ self._jconf = None
+ self._conf = {}
def set(self, key, value):
"""Set a configuration property."""
- self._jconf.set(key, unicode(value))
+ # Try to set self._jconf first if JVM is created, set self._conf
if JVM is not created yet.
+ if self._jconf:
+ self._jconf.set(key, unicode(value))
+ else:
+ # Don't use unicode for self._conf, otherwise we will get
exception when launching jvm.
+ self._conf[key] = value
--- End diff --
hmm, I didn't get any exception. Here is what I tried
```
$ SPARK_HOME=$PWD PYTHONPATH=python:python/lib/py4j-0.10.3-src.zip python
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyspark import SparkContext
>>> from pyspark import SparkConf
>>> conf = SparkConf().set("spark.driver.memory", "4g")
>>> sc = SparkContext(conf=conf)
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel).
16/09/26 16:53:58 WARN NativeCodeLoader: Unable to load native-hadoop
library for your platform... using builtin-java classes where applicable
16/09/26 16:53:58 WARN Utils: Your hostname, resolves to a loopback
address: 127.0.1.1; using *.*.*.* instead (on interface )
16/09/26 16:53:58 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to
another address
>>> conf.get("spark.driver.memory")
u'4g'
>>> sc.getConf().get("spark.driver.memory")
u'4g'
```
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]