From 605936f15c447d436e33fb59913f128eb70a62fd Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 4 Jun 2010 14:15:10 -0700 Subject: [PATCH] Defending against one possible flaw in original() which isn't currently a problem but may become so. --- eventlet/patcher.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/eventlet/patcher.py b/eventlet/patcher.py index 77d8e42..f7fc87e 100644 --- a/eventlet/patcher.py +++ b/eventlet/patcher.py @@ -151,6 +151,10 @@ def _original_patch_function(func, *module_names): def original(modname): """ This returns an unpatched version of a module; this is useful for 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 if original_name in sys.modules: return sys.modules.get(original_name) @@ -159,6 +163,11 @@ def original(modname): # dict; be sure to restore whatever module had that name already saver = SysModulesSaver((modname,)) 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: real_mod = __import__(modname, {}, {}, modname.split('.')[:-1]) # hacky hack: Queue's constructor imports threading; therefore