aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/pyspark/serializers.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/python/pyspark/serializers.py b/python/pyspark/serializers.py
index 1b52c144df..a10f85b55a 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,