Repository: spark
Updated Branches:
  refs/heads/branch-1.1 aa7a48ee9 -> 2225d18a7


[SPARK-1687] [PySpark] fix unit tests related to pickable namedtuple

serializer is imported multiple times during doctests, so it's better to make 
_hijack_namedtuple() safe to be called multiple times.

Author: Davies Liu <[email protected]>

Closes #1771 from davies/fix and squashes the following commits:

1a9e336 [Davies Liu] fix unit tests

(cherry picked from commit 9fd82dbbcb8b10debbe95f1acab53ae8b340f38e)
Signed-off-by: Josh Rosen <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/2225d18a
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/2225d18a
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/2225d18a

Branch: refs/heads/branch-1.1
Commit: 2225d18a751b7a4470a93f3d9edebe0d33df75c8
Parents: aa7a48e
Author: Davies Liu <[email protected]>
Authored: Mon Aug 4 15:54:52 2014 -0700
Committer: Josh Rosen <[email protected]>
Committed: Mon Aug 4 15:55:12 2014 -0700

----------------------------------------------------------------------
 python/pyspark/serializers.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/2225d18a/python/pyspark/serializers.py
----------------------------------------------------------------------
diff --git a/python/pyspark/serializers.py b/python/pyspark/serializers.py
index 1b52c14..a10f85b 100644
--- a/python/pyspark/serializers.py
+++ b/python/pyspark/serializers.py
@@ -297,8 +297,11 @@ def _hack_namedtuple(cls):
 
 def _hijack_namedtuple():
     """ Hack namedtuple() to make it picklable """
-    global _old_namedtuple # or it will put in closure
+    # hijack only one time
+    if hasattr(collections.namedtuple, "__hijack"):
+        return
 
+    global _old_namedtuple # or it will put in closure
     def _copy_func(f):
         return types.FunctionType(f.func_code, f.func_globals, f.func_name,
                 f.func_defaults, f.func_closure)
@@ -313,6 +316,7 @@ def _hijack_namedtuple():
     collections.namedtuple.func_globals["_old_namedtuple"] = _old_namedtuple
     collections.namedtuple.func_globals["_hack_namedtuple"] = _hack_namedtuple
     collections.namedtuple.func_code = namedtuple.func_code
+    collections.namedtuple.__hijack = 1
 
     # hack the cls already generated by namedtuple
     # those created in other module can be pickled as normal,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to