a question in python curses modules

Sion Arrowsmith siona at chiark.greenend.org.uk
Fri Feb 15 10:10:12 EST 2008


Marc 'BlackJack' Rintsch  <bj_666 at gmx.net> wrote:
>When the interpreter shuts down it has to remove objects.  Everything you
>need in a `__del__()` method must be referenced by that object to be sure
>that it is still there and not already garbage collected.  *But* it's not
>guaranteed that `__del__()` is called at all!

This may be true, but it's not really the point here, since clearly
__del__() *is* being called, otherwise how would the OP know that
curses was None in it?

What's relevant is the consequences of the first two sentences. As
the interpreter shuts down, it removes objects *and you don't know
what order it's going to do that in*. So what is happening here is
that first the curses module is being removed (and the name "curses"
bound to None instead), and then the CursesObject instance is
removed, which causes its __del__ to be called with curses == None.

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list