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


Groups > comp.lang.python > #104180

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

From "Veek. M" <vek.m1234@gmail.com>
Newsgroups comp.lang.python
Subject __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.
Date 2016-03-07 08:57 +0530
Organization Home
Message-ID <nbiscc$v96$1@dont-email.me> (permalink)

Show all headers | View raw


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

2. What happens when I SystemExit? __del__ and gc are not invoked when I 
SystemExit and there's a circular reference - but why? The OS is going 
to reclaim the memory anyways so why be finicky about circular 
references - why can't we go ahead and call __dell_ and run gc?

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

What happens here to prevent a NameError? Apparently without the foo=foo 
a NameError can occur? But why? import foo creates a reference to the 
object anyways so it's refcount will be above 0 anyways till __del__ is 
called.


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

Back to comp.lang.python | Previous | NextNext 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