multiprocessing包
from multiprocessing import Pool def a(num): print num if __name__ == "__main__": pool = Pool(3) for i in range(10): pool.apply_async(a,args=(i,)) pool.close() pool.join()
concurrent包
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: for item in number_list: executor.submit(evaluate_item, item)
参考资料
https://python-parallel-programmning-cookbook.readthedocs.io/zh_CN/latest/chapter4/02_Using_the_concurrent.futures_Python_modules.html