Self healthcheck
Asaf Las
roegltd at gmail.com
Wed Jan 22 11:03:53 EST 2014
On Wednesday, January 22, 2014 10:56:30 AM UTC+2, Frank Millman wrote:
>
> class MainObject:
> def __init__(self, identifier):
> self._del = delwatcher('MainObject', identifier)
> class delwatcher:
> def __init__(self, obj_type, identifier):
> self.obj_type = obj_type
> self.identifier = identifier
> log('{}: id={} created'.format(self.obj_type, self.identifier))
> def __del__(self):
> log('{}: id={} deleted'.format(self.obj_type, self.identifier))
> If you do find that an object is not being deleted, it is then
> trial-and-error to find the problem and fix it. It is probably a circular
> reference
>
> Frank Millman
Thanks Frank. Good approach!
One question - You could do:
class MainObject:
def __init__(self, identifier):
self._del = delwatcher(self)
then later
class delwatcher:
def __init__(self, tobject):
self.obj_type = type(tobject)
self.identifier = id(tobject)
...
when creating delwatcher. Was there special reason to not to use them?
is this because of memory is reused when objects are deleted
and created again so same reference could be for objects created
in different time slots?
Thanks
Asaf
More information about the Python-list
mailing list