python3 多线程查找
code
import threading import time from queue import Queue def test(data,que,index): for i in data: if(i==8900): que.put(i) print(index,"------",i) pass if __name__ == "__main__": que=Queue() searchl=[ i for i in range(10000) ] pro_pool=[] pro_num=12 #每个进程处理任务数量 per_num=int(len(searchl)/pro_num) print(per_num) #余数 lef=len(searchl)%pro_num for i in range(pro_num): print(per_num*i,per_num*(i+1)) if(i==(pro_num-1) and (not lef==0)): tmp=threading.Thread(target=test,args=(searchl[per_num*i:per_num*(i+1)+lef],que,i)) else: tmp=threading.Thread(target=test,args=(searchl[per_num*i:per_num*(i+1)],que,i)) tmp.name = "progress{}".format(i) tmp.daemon = True pro_pool.append(tmp) tmp.start() while(True): v=que.get() if(v): print(v) break print("main")