1.Pool的用法
#!/usr/bin/env python# -*- coding: utf-8 -*-'''@author: Shiyu Huang@contact: huangsy13@gmail.com@file: asy_test.py'''import numpy as npimport multiprocessingfrom multiprocessing import Process, Poolimport timedef test_func(x): x = x+1 print x time.sleep(3) print 'end' return xif __name__ == '__main__': test_size = 20 number = np.zeros(test_size).tolist() for i in range(len(number)): number[i] = i pool = Pool(processes=multiprocessing.cpu_count()) # for i in range(test_size): # pool.apply_async(test_func, (number[i])) resultList = pool.map(test_func,number) pool.close() pool.join() print resultList