diff --git a/python/ray/cloudpickle/cloudpickle_fast.py b/python/ray/cloudpickle/cloudpickle_fast.py index fcff7d83b..84f373001 100644 --- a/python/ray/cloudpickle/cloudpickle_fast.py +++ b/python/ray/cloudpickle/cloudpickle_fast.py @@ -186,15 +186,26 @@ def _class_getstate(obj): clsdict.pop('_abc_cache', None) clsdict.pop('_abc_negative_cache', None) clsdict.pop('_abc_negative_cache_version', None) + # these are generated by some thirdparty libraries + clsdict.pop('_abc_generic_negative_cache', None) + clsdict.pop('_abc_generic_negative_cache_version', None) + registry = clsdict.pop('_abc_registry', None) if registry is None: - # in Python3.7+, the abc caches and registered subclasses of a - # class are bundled into the single _abc_impl attribute - clsdict.pop('_abc_impl', None) - (registry, _, _, _) = abc._get_dump(obj) + if hasattr(abc, '_get_dump'): + # in Python3.7+, the abc caches and registered subclasses of a + # class are bundled into the single _abc_impl attribute + clsdict.pop('_abc_impl', None) + (registry, _, _, _) = abc._get_dump(obj) - clsdict["_abc_impl"] = [subclass_weakref() - for subclass_weakref in registry] + clsdict["_abc_impl"] = [subclass_weakref() + for subclass_weakref in registry] + else: + # FIXME(suquark): The upstream cloudpickle cannot work in Ray + # because sometimes both '_abc_registry' and '_get_dump' does + # not exist. Some strange typing objects may cause this issue. + # Here the workaround just set "_abc_impl" to None. + clsdict["_abc_impl"] = None else: # In the above if clause, registry is a set of weakrefs -- in # this case, registry is a WeakSet