[Python-Dev] Fun with 2.3 shutdown
Armin Rigo
arigo at tunes.org
Tue Sep 23 12:49:09 EDT 2003
Hello Phillip,
On Tue, Sep 23, 2003 at 12:09:18PM -0400, Phillip J. Eby wrote:
> So, unless a module's dictionary were to reference the module (or functions
> were to reference the module rather than (or in addition to) the module
> dictionary), it seems the proposed semantics would lead to unexpected
> results.
Right.
I'm not sure I understand the reasons behind the current module/globals
relationship. As modules zap their globals with None when they are
deallocated, we observe the following behavior:
(foo.py)
def g():
return 5
def f():
return g()
>>> from foo import f
>>> import sys; del sys.modules['test4']
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "foo.py", line 4, in f
return g()
TypeError: 'NoneType' object is not callable
Possibly far-fetched, but I wouldn't be surprized to find large applications
that mess with sys.modules in some way. For example, in one case, to ensure
that a whole collection of interdependent modules will be reloaded on demand
after I detect a change in one of them, I'm simply removing them all from
sys.modules.
Armin
More information about the Python-Dev
mailing list