[pypy-issue] [issue1514] module behaviour incompatibility which makes eventlet fail

Amaury Forgeot d Arc tracker at bugs.pypy.org
Tue Jun 11 12:32:29 CEST 2013

Amaury Forgeot d Arc <amauryfa at gmail.com> 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...

nosy: +amaury

PyPy bug tracker <tracker at bugs.pypy.org>

More information about the pypy-issue mailing list