Python references and practical solutions to reference-related problems (#79)

Dr. Tim Couper bio
30min Intermediate
categories: best-practices, core, technique

The talk gives a clear presentation of:
 
* Reference counting (sys.getrefcount and how it works)
* Circular references (gc.collect as a means of finding them)
* Weak references (weakref.ref as a means of resolution)
* Pickling classes with weak references (cPickle/pickle module, __getstate__, __setstate__)
 
Along the way, we'll introduce a couple of interesting patterns which can be used to solve common classes of circular reference problems. As a side-benefit, the patterns demonstrate the clean and practical uses of properties and mixin classes (how to make a pickleable, circular-reference-free subclass of a pickleable, circular-reference-strapped class), and, of course, use the unittest framework to check that our classes always stays circular-reference-free.
 


Files:




# Permalink