fork(1) download
  1. import pickle
  2.  
  3. class ThingHolder:
  4. __slots__ = ['thing']
  5. def __init__(self, thing):
  6. print(self, thing)
  7. self.thing = thing
  8. def __reduce__(self):
  9. return (ThingHolder, (self.thing,))
  10.  
  11. th = ThingHolder(None)
  12. th.thing = th
  13.  
  14. th2 = pickle.loads(pickle.dumps(th, pickle.HIGHEST_PROTOCOL))
  15.  
  16. print(th2, th2.thing)
Runtime error #stdin #stdout #stderr 0.05s 10216KB
stdin
Standard input is empty
stdout
<__main__.ThingHolder object at 0x2b0f43241408> None
stderr
Traceback (most recent call last):
  File "./prog.py", line 14, in <module>
RecursionError: maximum recursion depth exceeded while calling a Python object