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


Groups > comp.lang.python > #64487

Re: Self healthcheck

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'causing': 0.04; 'cpython': 0.05; 'created,': 0.09; 'finished.': 0.09; 'identifier': 0.09; 'input,': 0.09; 'method,': 0.09; 'prevents': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'wrote': 0.14; '__del__': 0.16; 'concern,': 0.16; 'deleted,': 0.16; 'identifier.': 0.16; 'leaks': 0.16; 'mutable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'somewhere.': 0.16; 'subject:Self': 0.16; 'fix': 0.17; 'bit': 0.19; 'finished': 0.19; 'later': 0.20; 'spread': 0.22; 'circular': 0.24; 'skip:n 60': 0.24; 'question': 0.24; 'class.': 0.26; 'logging': 0.26; 'somewhere': 0.26; 'header:X-Complaints- To:1': 0.27; 'record': 0.27; 'code': 0.31; 'concern.': 0.31; 'explained': 0.31; 'obscure': 0.31; 'piece': 0.31; 'class': 0.32; 'probably': 0.32; 'skip:c 30': 0.32; 'running': 0.33; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'could': 0.34; 'problem': 0.35; 'problem.': 0.35; 'but': 0.35; 'there': 0.35; 'similar': 0.36; 'being': 0.38; 'server': 0.38; 'tasks': 0.38; 'to:addr:python- list': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'ensure': 0.60; 'remove': 0.60; 'information,': 0.61; 'due': 0.66; 'yes': 0.68; 'frank': 0.68; 'detecting': 0.84; 'tricky': 0.84; 'worry,': 0.84; 'good,': 0.91; 'mistakes': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Frank Millman" <frank@chagford.com>
Subject Re: Self healthcheck
Date Wed, 22 Jan 2014 10:56:30 +0200
References <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> <mailman.5829.1390360114.18130.python-list@python.org> <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com>
X-Gmane-NNTP-Posting-Host 197.87.184.242
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5832.1390381001.18130.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390381001 news.xs4all.nl 2880 [2001:888:2000:d::a6]:42219
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64487

Show key headers only | View raw


"Asaf Las" <roegltd@gmail.com> wrote in message 
news:58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com...
>
> Yes the question was about CPython. But i am not after CPython leaks
> though detecting these would be good, but my own mistakes leading to
> accumulation of data in mutable structures.
> there will be few processes running python code standalone communicating
> across servers and every activity will be spread over time so
> i have to persistently keep record of activity and remove it later when
> activity is finished.

I had a similar concern. My main worry, which turned out to be well-founded, 
was that I would create an object as a result of some user input, but when 
the user had finished with it, and in theory it could be garbage-collected, 
in practice it would not be due to some obscure circular reference 
somewhere.

For short-running tasks this is not a cause for concern, but for a 
long-running server these can build up over time and end up causing a 
problem.

My solution was to log every time an object was created, with some 
self-identifying piece of information, and then log when it was deleted, 
with the same identifier. After running the program for a while I could then 
analyse the log and ensure that each creation had a corresponding deletion.

The tricky bit was logging the deletion. It is a known gotcha in Python that 
you cannot rely on the __del__ method, and indeed it can cause a circular 
reference in itself which prevents the object from being garbage-collected. 
I found a solution somewhere which explained the use of a 'delwatcher' 
class. This is how it works -

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))

In this case calling __del__() is safe, as no reference to the main object 
is held.

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

HTH

Frank Millman


Back to comp.lang.python | Previous | NextPrevious in thread | Next 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