using modules in destructors

MRAB google at
Tue Oct 28 17:34:04 CET 2008

On Oct 27, 5:40 pm, Scott David Daniels <Scott.Dani... at Acm.Org> wrote:
> samtyg... at wrote:
> > It seems to me that deleting local instances before imported modules
> > would solve the problem. Is it not possible for the interpreter to get
> > this right? Or are there cases where this would break stuff.
> > It seems rather unpythonic for the __del__() method to become
> > unpredictable at exit.
> What would you have different? How would you define the end of a
> Python program?  Would all modules and globals remain, and then
> darkness?  Would the modules get removed in alphabetical order?
> ....
I suppose the modules could be removed in the reverse order in which
they were loaded, excepting cross-references (two objects from
different modules referring to their own modules and each other). Even
neglecting modules, if two objects have destructors and refer to each
other, which should be collected first?

> The core of the problem is that there is ((and possibly can be)
> no good definition of what happens after SystemExit leaves the
> __main__ module.
> --Scott David Daniels
> Scott.Dani... at Acm.Org

More information about the Python-list mailing list