冻结我有如下使用nose_parameterized一个Python代码:多线程的urllib2鼻子框架
from nose_parameterized import parameterized
from multiprocessing.pool import ThreadPool
import urllib2
def make_http_call(url, req_type):
opener = urllib2.build_opener() # <=== this line causes it to freeze
return 1
pool = ThreadPool(processes=4)
results = []
urls = ['a', 'b', 'c', 'd']
for url in urls:
results.append(pool.apply_async(make_http_call, (url, 'html')))
d = {'add': []}
for ind, res in enumerate(results):
d['add'].append((res.get(), 2+ind, 3+ind))
@parameterized(d['add'])
def test_add(a, b, c):
assert a+b == c
这是代码的虚拟版本。基本上,我需要使用http请求响应加载测试参数,并且由于有很多网址,我想多线程化它们。 只要我添加urllib2.build_opener,它使用鼻子冻结(但仍然可以与python很好地工作) 另外,我试过urllib2.urlopen;一样的问题。 是否有'正确'(可调试)解决方法的任何想法?
也许这会[帮助](http://stackoverflow.com/questions/2137187/python-process-blocked-by-urllib2) – 2014-12-05 20:48:32
谢谢。我知道你关联的那个问题,但是我不能将任何东西放在__main__中,因为在参数收集之后执行安装程序,所以不能在鼻子安装中进行设置。鉴于限制,我希望有一个解决方法。 – max 2014-12-05 21:14:02