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

    https://github.com/apache/spark/pull/18734#discussion_r133609212
  
    --- Diff: python/pyspark/cloudpickle.py ---
    @@ -241,11 +338,32 @@ def save_function(self, obj, name=None):
                 if getattr(themodule, name, None) is obj:
                     return self.save_global(obj, name)
     
    +        # a builtin_function_or_method which comes in as an attribute of 
some
    +        # object (e.g., object.__new__, itertools.chain.from_iterable) 
will end
    +        # up with modname "__main__" and so end up here. But these 
functions
    +        # have no __code__ attribute in CPython, so the handling for
    +        # user-defined functions below will fail.
    +        # So we pickle them here using save_reduce; have to do it 
differently
    +        # for different python versions.
    +        if not hasattr(obj, '__code__'):
    +            if PY3:
    +                if sys.version_info < (3, 4):
    +                    raise pickle.PicklingError("Can't pickle %r" % obj)
    +                else:
    +                    rv = obj.__reduce_ex__(self.proto)
    +            else:
    +                if hasattr(obj, '__self__'):
    +                    rv = (getattr, (obj.__self__, name))
    +                else:
    +                    raise pickle.PicklingError("Can't pickle %r" % obj)
    +            return Pickler.save_reduce(self, obj=obj, *rv)
    +
             # if func is lambda, def'ed at prompt, is in main, or is nested, 
then
             # we'll pickle the actual function object rather than simply 
saving a
             # reference (as is done in default pickler), via 
save_function_tuple.
    -        if islambda(obj) or obj.__code__.co_filename == '<stdin>' or 
themodule is None:
    -            #print("save global", islambda(obj), obj.__code__.co_filename, 
modname, themodule)
    +        if (islambda(obj)
    --- End diff --
    
    Just as a side note, it looks this PR includes 
https://github.com/cloudpipe/cloudpickle/pull/51 too (SPARK-21753).


---
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.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to