diff options
author | Davies Liu <davies.liu@gmail.com> | 2014-09-24 13:00:05 -0700 |
---|---|---|
committer | Josh Rosen <joshrosen@apache.org> | 2014-09-24 13:00:05 -0700 |
commit | bb96012b7360b099a19fecc80f0209b30f118ada (patch) | |
tree | 03d5224e97d17e05122d35ef8a95e96d87267725 /python/pyspark/tests.py | |
parent | c854b9fcb5595b1d70b6ce257fc7574602ac5e49 (diff) | |
download | spark-bb96012b7360b099a19fecc80f0209b30f118ada.tar.gz spark-bb96012b7360b099a19fecc80f0209b30f118ada.tar.bz2 spark-bb96012b7360b099a19fecc80f0209b30f118ada.zip |
[SPARK-3679] [PySpark] pickle the exact globals of functions
function.func_code.co_names has all the names used in the function, including name of attributes. It will pickle some unnecessary globals if there is a global having the same name with attribute (in co_names).
There is a regression introduced by #2144, revert part of changes in that PR.
cc JoshRosen
Author: Davies Liu <davies.liu@gmail.com>
Closes #2522 from davies/globals and squashes the following commits:
dfbccf5 [Davies Liu] fix bug while pickle globals of function
Diffstat (limited to 'python/pyspark/tests.py')
-rw-r--r-- | python/pyspark/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/python/pyspark/tests.py b/python/pyspark/tests.py index 4483bf80db..d1bb2033b7 100644 --- a/python/pyspark/tests.py +++ b/python/pyspark/tests.py @@ -213,6 +213,24 @@ class SerializationTestCase(unittest.TestCase): out2 = ser.loads(ser.dumps(out1)) self.assertEquals(out1, out2) + def test_func_globals(self): + + class Unpicklable(object): + def __reduce__(self): + raise Exception("not picklable") + + global exit + exit = Unpicklable() + + ser = CloudPickleSerializer() + self.assertRaises(Exception, lambda: ser.dumps(exit)) + + def foo(): + sys.exit(0) + + self.assertTrue("exit" in foo.func_code.co_names) + ser.dumps(foo) + class PySparkTestCase(unittest.TestCase): |