Advertisement
rfmonk

weakref_weakgraph.py

Jan 15th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import gc
  5. from pprint import pprint
  6. import weakref
  7.  
  8. from weakref_graph import Graph, demo
  9.  
  10.  
  11. class WeakGraph(Graph):
  12.     def set_next(self, other):
  13.         if other is not None:
  14.             # See if we should replace the reference
  15.             # to other with a weakref.
  16.             if self in other.all_nodes():
  17.                 other = weakref.proxy(other)
  18.         super(WeakGraph, self).set_next(other)
  19.         return
  20.  
  21. demo(WeakGraph)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement