Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1460#discussion_r15137226
  
    --- Diff: python/pyspark/serializers.py ---
    @@ -297,6 +297,33 @@ class MarshalSerializer(FramedSerializer):
         loads = marshal.loads
     
     
    +class AutoSerializer(FramedSerializer):
    +    """
    +    Choose marshal or cPickle as serialization protocol autumatically
    +    """
    +    def __init__(self):
    +        FramedSerializer.__init__(self)
    +        self._type = None
    +
    +    def dumps(self, obj):
    +        try:
    +            if self._type is not None:
    +                raise TypeError("fallback")
    +            return 'M' + marshal.dumps(obj)
    +        except Exception:
    +            self._type = 'P'
    +            return 'P' + cPickle.dumps(obj, -1)
    --- End diff --
    
    I had add an fast path for it, no exception cost any more.


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

Reply via email to