[Python-3000] Draft PEP: Module Initialization and finalization

"Martin v. Löwis" martin at v.loewis.de
Wed Apr 12 18:43:27 CEST 2006


Thomas Wouters wrote:
> Actually, no, reload() has to remove the module from sys.modules and
> load it anew.

That's not what reload currently does for Python modules. The module
object stays the same (so that anybody who imported it will also see
the reload's effect).

> The reason for this is that any instances of types defined
> in the module can still live, after the reload, and they would still
> refer to their old-module-object-referring types. (And, as you said,
> this is a reason to keep the 'state' in module objects.)

Are you expecting that reload of an extension module will actually
load the current code from disk? This can't really work: on some
systems, you can't update the DLL while it is in use; on others,
it might not be possible to load the same shared library twice.

>     This raises the question whether modules should be able to
>     participate in cyclic GC... 
> 
> Don't they already? They have a traverse proc, just not a clear proc.

Sure: for the state that is common to all modules. For the per-module
state, traverse functionality might also be needed, which would mean
that the module needs to implement it.

Regards,
Martin


More information about the Python-3000 mailing list