import pickle class ThingHolder: __slots__ = ['thing'] def __init__(self, thing): print(self, thing) self.thing = thing def __reduce__(self): return (ThingHolder, (self.thing,)) th = ThingHolder(None)th.thing = th th2 = pickle.loads(pickle.dumps(th, pickle.HIGHEST_PROTOCOL)) print(th2, th2.thing)
Standard input is empty
<__main__.ThingHolder object at 0x2b0f43241408> None
Traceback (most recent call last): File "./prog.py", line 14, in <module> RecursionError: maximum recursion depth exceeded while calling a Python object
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!