Closed
Description
Continuing a discussion from #439, and as pointed out by @raopku, the following does not work.
import ray
ray.init()
import cloudpickle
class A(object):
pass
@ray.remote
class B(A):
def __init__(self):
super(B, self).__init__()
B.remote()
At the root of the problem is the fact that cloudpickle
doesn't seem to be able to serialize subclasses that call super
. For example, consider the following.
import cloudpickle
class A(object):
pass
class B(A):
def __init__(self):
super(B, self).__init__()
cloudpickle.dumps(B)
The last line fails with the following exception.
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
/Users/rkn/anaconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py in dump(self, obj)
145 try:
--> 146 return Pickler.dump(self, obj)
147 except RuntimeError as e:
/Users/rkn/anaconda3/lib/python3.6/pickle.py in dump(self, obj)
408 self.framer.start_framing()
--> 409 self.save(obj)
410 self.write(STOP)
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save(self, obj, save_persistent_id)
475 if f is not None:
--> 476 f(self, obj) # Call unbound method with explicit self
477 return
/Users/rkn/anaconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py in save_global(self, obj, name, pack)
424
--> 425 self.save_reduce(typ, (obj.__name__, obj.__bases__, d), obj=obj)
426 else:
/Users/rkn/anaconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py in save_reduce(self, func, args, state, listitems, dictitems, obj)
585 save(func)
--> 586 save(args)
587 write(pickle.REDUCE)
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save(self, obj, save_persistent_id)
475 if f is not None:
--> 476 f(self, obj) # Call unbound method with explicit self
477 return
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save_tuple(self, obj)
735 for element in obj:
--> 736 save(element)
737 # Subtle. Same as in the big comment below.
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save(self, obj, save_persistent_id)
475 if f is not None:
--> 476 f(self, obj) # Call unbound method with explicit self
477 return
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save_dict(self, obj)
820 self.memoize(obj)
--> 821 self._batch_setitems(obj.items())
822
/Users/rkn/anaconda3/lib/python3.6/pickle.py in _batch_setitems(self, items)
846 save(k)
--> 847 save(v)
848 write(SETITEMS)
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save(self, obj, save_persistent_id)
475 if f is not None:
--> 476 f(self, obj) # Call unbound method with explicit self
477 return
/Users/rkn/anaconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py in save_function(self, obj, name)
263 or themodule is None):
--> 264 self.save_function_tuple(obj)
265 return
/Users/rkn/anaconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py in save_function_tuple(self, func)
311 save(_make_skel_func)
--> 312 save((code, closure, base_globals))
313 write(pickle.REDUCE)
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save(self, obj, save_persistent_id)
475 if f is not None:
--> 476 f(self, obj) # Call unbound method with explicit self
477 return
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save_tuple(self, obj)
735 for element in obj:
--> 736 save(element)
737 # Subtle. Same as in the big comment below.
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save(self, obj, save_persistent_id)
475 if f is not None:
--> 476 f(self, obj) # Call unbound method with explicit self
477 return
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save_list(self, obj)
780 self.memoize(obj)
--> 781 self._batch_appends(obj)
782
/Users/rkn/anaconda3/lib/python3.6/pickle.py in _batch_appends(self, items)
807 elif n:
--> 808 save(tmp[0])
809 write(APPEND)
... last 16 frames repeated, from the frame below ...
/Users/rkn/anaconda3/lib/python3.6/pickle.py in save(self, obj, save_persistent_id)
475 if f is not None:
--> 476 f(self, obj) # Call unbound method with explicit self
477 return
RecursionError: maximum recursion depth exceeded in comparison
During handling of the above exception, another exception occurred:
PicklingError Traceback (most recent call last)
<ipython-input-2-e105f7705909> in <module>()
----> 1 cloudpickle.dumps(B)
/Users/rkn/anaconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py in dumps(obj, protocol)
704
705 cp = CloudPickler(file,protocol)
--> 706 cp.dump(obj)
707
708 return file.getvalue()
/Users/rkn/anaconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py in dump(self, obj)
148 if 'recursion' in e.args[0]:
149 msg = """Could not pickle object as excessively deep recursion required."""
--> 150 raise pickle.PicklingError(msg)
151
152 def save_memoryview(self, obj):
PicklingError: Could not pickle object as excessively deep recursion required.