multiprocessing.dummy replicates the API of multiprocessing but is no more than a wrapper around the threading module.

以上是python官方文档对multiprocessing.dummy的介绍。

简单地说,multiprocessing.dummy是multiprocessing多进程模块复制的一个多线程模块,API都是通用的。

它非常强大!你读取源码会很有收获!

我尝试用thread模块ssh登录数百台机器获取docker containers用时90s以上;换成multiprocessing.dummy,processes=12,用时7s!

使用方法:

from multiprocessing.dummy import Pool as ThreadPool 
pool = ThreadPool(processes=4)
data = pool.map(func, args)
pool.close()
pool.join()
#data = pool.map_async(func, args).get()

·End·