pythone 多线程池 & 多进程池
I/O 用线程
运算 用进程
实际当中可加time.time测试。那种快用那种。
map类型
map_async() 回调 return
map() 随机读取
imap() 顺序读取(Pool(1)可用于二次排序)
线程和进程在于.dummy
多线程
from multiprocessing.dummy import Pool
def test(num):
print(num)
if __name__ == '__main__':
list = [1,2,3,4]
pool = Pool(2)
pool.map(test,list)
pool.close()
pool.join()
多进程
from multiprocessing import Pool
def test(num):
print(num)
if __name__ == '__main__':
list = [1,2,3,4]
pool = Pool(2)
pool.map(test,list)
pool.close()
pool.join()