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


Groups > comp.lang.python > #104182

Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.
Date Mon, 07 Mar 2016 14:42:15 +1100
Lines 38
Message-ID <mailman.5.1457322150.10335.python-list@python.org> (permalink)
References <nbiscc$v96$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de /msu0DqKDkh6eiRAmKD7nwPT7u63o9HOYDluqQtMtKHA==
Cancel-Lock sha1:DSn0Dy/LOKSRcrj/iA4H2QnK07E=
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.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'calls.': 0.07; 'method,': 0.07; 'garbage': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'example:': 0.10; 'def': 0.13; '__del__': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'relates': 0.16; 'simple)': 0.16; 'subject:when': 0.16; 'systemexit': 0.16; 'too?': 0.16; 'circular': 0.18; 'windows': 0.20; 'class,': 0.22; 'exists.': 0.22; 'appears': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X -Complaints-To:1': 0.26; 'dos': 0.27; 'function': 0.28; 'subject:/': 0.30; 'system,': 0.30; 'minimal': 0.30; 'rules': 0.31; 'skip:_ 10': 0.32; 'run': 0.33; 'point': 0.33; 'foo': 0.33; 'advice': 0.35; 'clear': 0.35; 'functions.': 0.35; 'subject:use': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'method': 0.37; 'operating': 0.37; 'received:org': 0.37; 'mean': 0.38; 'to:addr:python.org': 0.40; 'mark': 0.40; 'more': 0.63; 'skip:\xe2 10': 0.70; '8bit%:46': 0.76; '_o__)': 0.84; 'coffin': 0.84; 'received:125': 0.84; 'subject:you': 0.85; "'don't": 0.91; 'canonical': 0.91; 'why?': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
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>
Xref csiph.com comp.lang.python:104182

Show key headers only | View raw


"Veek. M" <vek.m1234@gmail.com> writes:

> 1. What are the rules for using __del__ besides: 'don't use it'.

What do you mean by “rules”?

If you want advice on using that method, I don't think a canonical
exhaustive “rules” set exists.

For example: Use ‘__del__’ to mark an object as no longer used; don't
expect that to result in the object actually going away at any
particular point in time.

> 2. What happens when I SystemExit? __del__ and gc are not invoked when
> I SystemExit and there's a circular reference - but why?

So that we can have a concrete example: Can you give a (very minimal and
simple) example demonstrating the behaviour, so we can run it too?

> 3.
> import foo
> def __del__(self, foo=foo):
>   foo.bar()

That appears to be a module-level function. It is not a method of any
class, so I am not clear on how it relates to garbage collection.

> 4. also, are method calls more efficient than function calls?

All method calls are function calls. This is because all methods are
functions.

-- 
 \     “Unix is an operating system, OS/2 is half an operating system, |
  `\    Windows is a shell, and DOS is a boot partition virus.” —Peter |
_o__)                                                        H. Coffin |
Ben Finney

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


Thread

__del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls. "Veek. M" <vek.m1234@gmail.com> - 2016-03-07 08:57 +0530
  Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls. Chris Angelico <rosuav@gmail.com> - 2016-03-07 14:38 +1100
  Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls. Ben Finney <ben+python@benfinney.id.au> - 2016-03-07 14:42 +1100
  Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-07 16:56 +1100
  Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls. "Veek. M" <vek.m1234@gmail.com> - 2016-03-07 11:43 +0530
    Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-07 19:37 +1100
      Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls. "Veek. M" <vek.m1234@gmail.com> - 2016-03-07 16:56 +0530

csiph-web