scoping/module life puzzle

Michael Hudson mwh at python.net
Mon Dec 2 10:06:25 EST 2002


Robin Becker <robin at jessikat.fsnet.co.uk> writes:

> Is there some special reason why holding a reference to the code object
> created in m's __dict__ doesn't keep the module alive? 

It seems that when m goes away its __dict__ gets zapped, despite the
fact that there are other references to m.__dict__ (i.e. all the
func_globals in the functions created in m).

I guess this dates from before the cycle collector: previously these
functions would never have been collected as there's an obvious cycle:

f.func_globals['f'] is f

I wonder if this could be changed now we have the cycle collector?

Presumably the reason that at least not many people have run into this
before is that you're not really expected to create and destroy
modules on the fly.

Cheers,
M.

-- 
    -Dr. Olin Shivers,
     Ph.D., Cranberry-Melon School of Cucumber Science
                                           -- seen in comp.lang.scheme



More information about the Python-list mailing list