出處: 一行代码完成并行任务

核心結構:(媽的,這麼短,那以前搞 multithread 是搞心酸的嗎 QAQ)

from multiprocessing.dummy import Pool as ThreadPool
from libyour import function # functions or objects

pool = ThreadPool(4)
results = pool.map(function, objects)

result 裏面可能是物件指標或資料,端看 function 的返回是什麼。

Comments

comments powered by Disqus