Amaury Forgeot d Arc <[email protected]> added the comment:

Noteworthy fact:
"import select" will reload the module, AND store it in the current namespace
__import__('select') will reload the module BUT leave the old module in the 
namespace.

CPython and PyPy both initialize a builtin module only once, and make a shallow 
copy of its initial 
__dict__.  On the next import, this initial dict is used to refresh the module, 
no init function is called.

The difference is that CPython will create a new module instance each time, 
when PyPy has only one prebuilt 
instance (stored in space.builtin_modules).
This won't be a simple change.

As a workaround, instead of saving the module, you could save a copy of its 
__dict__ instead:

saved = sys.modules.get(modname).__dict__.copy()
...pop, import...
sys.modules[modname].__dict__.update(saved)

----------
nosy: +amaury

________________________________________
PyPy bug tracker <[email protected]>
<https://bugs.pypy.org/issue1514>
________________________________________
_______________________________________________
pypy-issue mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to