Spark can't pickle method_descriptor

前端 未结 2 423
北恋
北恋 2021-01-05 09:37

I get this weird error message

15/01/26 13:05:12 INFO spark.SparkContext: Created broadcast 0 from wholeTextFiles at NativeMethodAccessorImpl.java:-2
Traceba         


        
2条回答
  •  花落未央
    2021-01-05 10:16

    If it's really a pickling issue for a MethodDescriptorType, you could register how to pickle a MethodDescriptorType, with this:

    def _getattr(objclass, name, repr_str):
        # hack to grab the reference directly
        try:
            attr = repr_str.split("'")[3]
            return eval(attr+'.__dict__["'+name+'"]')
        except:
            attr = getattr(objclass,name)
            if name == '__dict__':
                attr = attr[name]
            return attar
    
    
    def save_wrapper_descriptor(pickler, obj):
        pickler = Pickler(file, protocol)
        pickler.save_reduce(_getattr, (obj.__objclass__, obj.__name__,
                                       obj.__repr__()), obj=obj)
        return
    
    # register the following "type" with:
    #     Pickler.dispatch[MethodDescriptorType] = save_wrapper_descriptor
    MethodDescriptorType = type(type.__dict__['mro'])
    

    Then, if you register the above to the pickling dispatch table that spark uses (as shown above, or with copy_reg), it may get past the pickling error.

提交回复
热议问题