Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'subsequent': 0.05; 'wednesday,': 0.07; '22,': 0.09; 'identifier': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'wrote': 0.14; 'deleted,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Self': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'later': 0.20; 'memory': 0.22; 'saying': 0.22; 'creating': 0.23; 'circular': 0.24; 'skip:n 60': 0.24; 'question': 0.24; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'appear': 0.29; 'correct': 0.29; 'object.': 0.31; 'them?': 0.31; 'class': 0.32; 'probably': 0.32; 'skip:c 30': 0.32; 'skip:_ 10': 0.34; 'received:co.za': 0.34; 'received:za': 0.34; 'skip:d 20': 0.34; 'could': 0.34; 'message.': 0.35; 'problem': 0.35; 'created': 0.35; 'case,': 0.35; 'objects': 0.35; 'there': 0.35; 'thanks': 0.36; 'january': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'identify': 0.61; 'different': 0.65; 'frank': 0.68; 'frequently': 0.68; 'received:41': 0.70; 'safe': 0.72; 'special': 0.74; 'exercise.': 0.84; 'do:': 0.91; 'reply,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: Self healthcheck Date: Thu, 23 Jan 2014 07:36:53 +0200 References: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> <9729ddaa-5976-4e53-8584-6198b47b6789@googlegroups.com> X-Gmane-NNTP-Posting-Host: 41-133-115-167.dsl.mweb.co.za X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390455427 news.xs4all.nl 2889 [2001:888:2000:d::a6]:55640 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64572 "Asaf Las" 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