OrbitzWorldwide/droned — pull request #27 by JustinVenus (2012-03-28 22:58:52+00:00)
Title: New Entity Feature

ParameterizedSingleton derived instances are now tracked with weak references to allow automatic garbage collection. Currently this feature is opt in as it may break a lot of droned if it were enabled by default at this time.

#example
from romeo.entity import Entity #or from droned.entity import Entity
class Foo(Entity):
"""Test class to demonstrate functionality"""
@classmethod
def _weak_callback(classObj, instanceId, obj):
if instanceId in classObj._instanceMap:
del classObj._instanceMap[instanceId]
print "Reaping unbound object id: %s" % str(instanceId)

def __init__(self, value):
self.reapable = bool(value % 2) #odds will automatically reap
_print('Created Foo(%d)' % (value,))
if self.reapable:
print "Foo(%d) will automatically gc when it leaves scope" % (value,)
else:
print "Foo(%d) will not gc without an explicit delete" % (value,)

#or run the full suite of tests
python %(sitelib)s/romeo/entity.py