Tightened up original's dependency-checking code in patcher, importing eventlet's subprocess in patcher_testso we can correctly timeout.

This commit is contained in:
Ryan Williams
2010-07-23 15:36:05 -07:00
parent 4a98a00d27
commit c6d04b3214
2 changed files with 16 additions and 11 deletions

View File

@@ -164,18 +164,23 @@ 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 # some rudimentary dependency checking -- fortunately the modules
# threading module # we're working on don't have many dependencies so we can just do
if modname == 'threading': # some special-casing here
saver.save('thread') deps = {'threading':'thread', 'Queue':'threading'}
sys.modules['thread'] = original('thread') if modname in deps:
dependency = deps[modname]
saver.save(dependency)
sys.modules[dependency] = original(dependency)
try: try:
real_mod = __import__(modname, {}, {}, modname.split('.')[:-1]) real_mod = __import__(modname, {}, {}, modname.split('.')[:-1])
# hacky hack: Queue's constructor imports threading; therefore if modname == 'Queue' and not hasattr(real_mod, '_threading'):
# we wrap it with something that ensures it always gets the # tricky hack: Queue's constructor in <2.7 imports
# original threading # threading on every instantiation; therefore we wrap
if modname == 'Queue': # it so that it always gets the original threading
real_mod.Queue.__init__ = _original_patch_function(real_mod.Queue.__init__, 'threading') real_mod.Queue.__init__ = _original_patch_function(
real_mod.Queue.__init__,
'threading')
# save a reference to the unpatched module so it doesn't get lost # save a reference to the unpatched module so it doesn't get lost
sys.modules[original_name] = real_mod sys.modules[original_name] = real_mod
finally: finally:

View File

@@ -1,6 +1,6 @@
import os import os
import shutil import shutil
import subprocess from eventlet.green import subprocess
import sys import sys
import tempfile import tempfile