Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2008 Doug Hellmann All rights reserved.
  5. #
  6. """Tools for demonstrating garbage collection
  7. """
  8. #end_pymotw_header
  9.  
  10. import gc
  11. from pprint import pprint
  12. import weakref
  13.  
  14. from weakref_graph import Graph, demo
  15.  
  16. class WeakGraph(Graph):
  17. def set_next(self, other):
  18. if other is not None:
  19. # See if we should replace the reference
  20. # to other with a weakref.
  21. if self in other.all_nodes():
  22. other = weakref.proxy(other)
  23. super(WeakGraph, self).set_next(other)
  24. return
  25.  
  26. demo(WeakGraph)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement