#threadpool的内部调用参数解析result = request.callable(*request.args, **request.kwds)# coding:utf-8import threadpool,timetime_list=[]args_list1=range(1,11)#如果要输入元组做参数,必须把元组转换成下面的形式args_list2=[(i,None) for i in zip(range(1,11),range(1,11))]print args_list2[((1, 1), None), ((2, 2), None), ((3, 3), None), ((4, 4), None), ((5, 5), None), ((6, 6), None), ((7, 7), None), ((8, 8), None), ((9, 9), None), ((10, 10), None)]#如果如果要输入字典做参数,必须把字典转换成下面的形式args_list3=[(None,{"a":1,"b":2}),(None,{"a":3,"c":4}),(None,{"a":5,"b":6})]#列表def handle_func1(a): return a#元组def handle_func2(*a,**b): return a#字典def handle_func3(*a,**b): return b#回调函数,会把处理函数的结果当参数def handle_func_callback(request,results): time_list.append(results)#创建连接池 ,最大连接数5pool=threadpool.ThreadPool(5)#处理函数handle_func*,处理函数的参数args_list*,处理函数的回调函数handle_func_callback(可以没有)requests1=threadpool.makeRequests(handle_func1,args_list1,handle_func_callback)requests2=threadpool.makeRequests(handle_func2,args_list2,handle_func_callback)requests3=threadpool.makeRequests(handle_func3,args_list3,handle_func_callback)#是将所有要运行多线程的请求扔进线程池[pool.putRequest(i) for i in requests1+requests2+requests3]#连接池挂起,第四行是等待所有的线程完成工作后退出pool.wait()print time_list#[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10),{'a': 1, 'b': 2}, {'a': 3, 'c': 4}, {'a': 5, 'b': 6}]import urllib2from multiprocessing.dummy import Pool as ThreadPooldef handle_func1(a): return apool = ThreadPool(4)#对range(11)的每一个数调用handle_func1,返回结果集results = pool.map(handle_func1, range(11))print resultspool.close()pool.join()