Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64572

Re: Self healthcheck

From "Frank Millman" <frank@chagford.com>
Subject Re: Self healthcheck
Date 2014-01-23 07:36 +0200
References <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> <mailman.5829.1390360114.18130.python-list@python.org> <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> <mailman.5832.1390381001.18130.python-list@python.org> <9729ddaa-5976-4e53-8584-6198b47b6789@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.5871.1390455427.18130.python-list@python.org> (permalink)

Show all headers | View raw


"Asaf Las" <roegltd@gmail.com> wrote in message 
news:9729ddaa-5976-4e53-8584-6198b47b6789@googlegroups.com...
> 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?
>

I read Dave's reply, and he is correct in saying that id's are frequently 
re-used in python.

However, in this particular case, I think you are right, it is safe to use 
the id to identify the object. An id can only be re-used if the original 
object is deleted, and that is the whole point of this exercise. We expect 
to see the id come up in a 'created' message, and then the same id appear in 
a 'deleted' message. If this happens, we are not concerned if the same id 
reappears in a subsequent 'created' message.

Frank


Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Self healthcheck Asaf Las <roegltd@gmail.com> - 2014-01-21 18:51 -0800
  Re: Self healthcheck Chris Angelico <rosuav@gmail.com> - 2014-01-22 14:08 +1100
    Re: Self healthcheck Asaf Las <roegltd@gmail.com> - 2014-01-22 00:18 -0800
      Re: Self healthcheck Nicholas Cole <nicholas.cole@gmail.com> - 2014-01-22 08:43 +0000
        Re: Self healthcheck Asaf Las <roegltd@gmail.com> - 2014-01-22 07:51 -0800
      Re: Self healthcheck "Frank Millman" <frank@chagford.com> - 2014-01-22 10:56 +0200
        Re: Self healthcheck Asaf Las <roegltd@gmail.com> - 2014-01-22 08:03 -0800
          Re: Self healthcheck Dave Angel <davea@davea.name> - 2014-01-22 13:40 -0500
          Re: Self healthcheck "Frank Millman" <frank@chagford.com> - 2014-01-23 07:36 +0200

csiph-web