[Serialization] Fix cloudpickle (#13242)

This commit is contained in:
Siyuan (Ryans) Zhuang
2021-01-06 17:21:17 -08:00
committed by GitHub
parent 02ae6c5a9a
commit dde49b8d48
+17 -6
View File
@@ -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