[Python-Dev] Problem between deallocation of modules and func_globals

Josiah Carlson jcarlson at uci.edu
Fri Jan 19 21:09:48 CET 2007


"Martin v. Löwis" <martin at v.loewis.de> wrote:
> 
> Josiah Carlson schrieb:
> > Seems to me like a bug, but the bug could be fixed if the module's
> > dictionary kept a (circular) reference to the module object.  Who else
> > has been waiting for a __module__ attribute?
> 
> This is the time machine at work:
> 
> py> import encodings
> py> encodings.search_function.__module__
> 'encodings'
> 
> It's a string, rather than the module object, precisely to avoid cyclic
> references.

I was saying that it would be nice if the following were true:

    >>> encodings.__module__
    <module 'encodings' from 'C:\python25\lib\encodings\__init__.pyc'>

That would make it easier for functions inside a module to pass around
references to the module namespace (I've had the need to do so before,
and have ended up using sys.modules[__name__], but that doesn't always
work).

So what if it is a circular reference (module references dict which
references module), we've got a GC which handles cycles just fine (when
users try not to be too smart).

 - Josiah



More information about the Python-Dev mailing list