Advertisement
Guest User

Python - Run a code at exit using weak references

a guest
Sep 10th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. """ Simulating atexit using weak references """
  2.  
  3. # Don't use this code - it is just for illustration.
  4. # Generally speaking it is better not to rely on order of
  5. # gc to implement a feature.
  6.  
  7. import weakref
  8.  
  9. class C: pass
  10.  
  11. def goodbye(param):
  12.     print 'Bye.',param
  13.  
  14. x=weakref.ref(C, goodbye)
  15.  
  16. if __name__ == '__main__':
  17.     print 3+4
  18.     print 8+9
  19.     print globals()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement