Python Multiple Threads Posted on 2016-12-11 | In python | visited: Python 多线程举例12345678910111213141516171819from multiprocessing import *NUM_THREAD = 10p = Pool(NUM_THREAD)start = 0offset = NUM_THREADqueries = get_quries("./test.txt") # 获取所有的任务列表cnt = 0 # 任务的数量while (start < len(queries)):end = start + offsetpool_queries = queries[start : end] # 每次取线程个数的任务列表rslt = p.map(get_qa_rslt, pool_queries) # get_qa_result 是一个函数,调用函数和当前线程的任务列表, rslt保存函数返回值for i in range(len(pool_queries)): q = pool_queries[i].strip() task = rslt[i] cnt += 1 print taskstart = end # 准备下一轮线程return cnt