2014年2月12日 星期三

A simple thread pool in Python

Implement a simple thread pool in a couple of lines.


from multiprocessing import Pool
from multiprocessing.dummy import Pool as ThreadPool
def f(x):
print("Test {}".format(str(x)))
pool = ThreadPool()
# pool = Pool() for process pool
pool.map(f, range(100))
pool.close()
pool.join()

沒有留言:

張貼留言