Defending against one possible flaw in original() which isn't currently a problem but may become so.

This commit is contained in:
Ryan Williams
2010-06-04 14:15:10 -07:00
parent 0793b503eb
commit 605936f15c

View File

@@ -151,6 +151,10 @@ def _original_patch_function(func, *module_names):
def original(modname): def original(modname):
""" This returns an unpatched version of a module; this is useful for """ This returns an unpatched version of a module; this is useful for
Eventlet itself (i.e. tpool).""" Eventlet itself (i.e. tpool)."""
# note that it's not necessary to temporarily install unpatched
# versions of all patchable modules during the import of the
# module; this is because none of them import each other, except
# for threading which imports thread
original_name = '__original_module_' + modname original_name = '__original_module_' + modname
if original_name in sys.modules: if original_name in sys.modules:
return sys.modules.get(original_name) return sys.modules.get(original_name)
@@ -159,6 +163,11 @@ def original(modname):
# dict; be sure to restore whatever module had that name already # dict; be sure to restore whatever module had that name already
saver = SysModulesSaver((modname,)) saver = SysModulesSaver((modname,))
sys.modules.pop(modname, None) sys.modules.pop(modname, None)
# install original thread module if we're getting the original
# threading module
if modname == 'threading':
saver.save('thread')
sys.modules['thread'] = original('thread')
try: try:
real_mod = __import__(modname, {}, {}, modname.split('.')[:-1]) real_mod = __import__(modname, {}, {}, modname.split('.')[:-1])
# hacky hack: Queue's constructor imports threading; therefore # hacky hack: Queue's constructor imports threading; therefore