def register(self, obj, resource):
def callback(ref):<EOL><INDENT>try:<EOL><INDENT>resource.close()<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>del self._table[id(resource)]<EOL><DEDENT>self._table[id(resource)] = weakref.ref(obj, callback)<EOL>
Register a resource to be closed with an object is collected.

When the given C{obj} is garbage-collected by the python interpreter,
the C{resource} will be closed by having its C{close()} method called.
Any exceptions are ignored.

@param obj: the object to track
@type obj: object
@param resource: the resource to close when the object is collected
@type resource: object